This is an old question, but no one seems to have mentioned it.
You are fortunate that this was generally related.
You needed to change
g++ -g -Wall -o my_binary -L/my/dir -lfoo bar.cpp
:
g++ -g -Wall -o my_binary -L/my/dir bar.cpp -lfoo
Your linker keeps track of the characters you need to resolve. If he first reads the library, he does not have the required characters, so he ignores the characters in it. List libraries after what you need. to reference them so that your linker has characters to find in them.
In addition, -lfoo does a search for a file named libfoo.a or libfoo.so as necessary. Not libfoo.so.0 . Therefore, either ln name or rename the library as appopriate.
To quote the gcc man page:
-l library ... It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.
Adding the file directly to the g++ line should work, unless, of course, you put it before bar.cpp , as a result of which the linker ignores it due to the lack of necessary characters, because the characters are not needed yet.
Michael Speer Nov 15 '16 at 5:34 2016-11-15 05:34
source share