GNU build question

How to find a library containing a definition of a specific function? I get a linker error.

+6
c linker
source share
3 answers

You can use the nm command line tool to display exported characters in binary files:

 ~/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 character is in the code segment (text), and in upper case means that it is public.

If you have the character you are looking for, you can use nm to make the characters exported by the library available, for example, 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.

+4
source share

If this is part of the standard C API, then just run man , he should clearly indicate where the function is defined.

+1
source share

If you want to find the library in a non-software way, you can find the LSB Navigator . Enter the function in the search field and check the library in the line with a green "status".

http://coldattic.info/pic/165509391387.png

This will be a β€œregular” library containing the function (in the example shown above, librt is the correct library for mq_unlink , so you are mq_unlink with -lrt ). Just contact this library and it will work on almost all Linux systems.

Note. I was one of the developers of the recommended tool.

+1
source share

All Articles