Reputation: 111
How to find the library, which contains the definition of particular function? I am getting linker error.
Upvotes: 6
Views: 145
Reputation: 99384
If you want to find out the library in non-programmatical way, you might find LSB Navigator useful. Enter the function into the search box, and check the library in the line with green "status".
(source: coldattic.info)
This will be the "conventional" library that contains the function (in the example depicted above, librt
is the correct library for mq_unlink
, so you link with -lrt
). Just link with that library, and it will work on virtually all Linux systems.
Note: I was one of the developers of the tool I recommend.
Upvotes: 1
Reputation: 400109
You can use the nm
command-line tool to list exported symbols in binaries:
~/src> cat nm-test.c
static int plus_four(int x)
{
return x + 4;
}
int sum_plus_four(int a, int b)
{
return plus_four(a + b);
}
int product_plus_four(int a, int b)
{
return plus_four(a * b);
}
~/src> gcc -c nm-test.c
~/src> nm ./nm-test.o
00000000 t plus_four
00000023 T product_plus_four
0000000b T sum_plus_four
According to the manual, 't' means that the symbol is in the code (text) segment, and uppercase means it's public.
If you have a symbol that you're looking for, you can use nm
to make the symbols exported by a library accessible to e.g. grep:
$ find -name lib*.a /example/library/path | xargs nm | grep -E "T $SYMBOL_TO_FIND"
This command-line is an untested sketch, but it should show the concept.
Upvotes: 4
Reputation: 165340
If it's part of the C standard API then just run man
, it should clearly state where the function is defined.
Upvotes: 1