I am working on a Linux platform and using the GNU C++ compiler. I am trying to resolve a link error that says some symbols are undefined. I can go find libraries with the name provided on the command line, and see that they contain the symbols in question ( using the ‘nm’ utility ).
I know that for the compilation step, I can use the command-line flag ‘-H’ instead of ‘-c’ in order to get a list of header files that were #included into the compilation. Is there a similar option for the linker? I figure if I could see the list of files that the linker used to handle each ‘-lmylibrary’ flag, I can troubleshoot further.
If you get an undefined symbol error it means you forgot to link some library, knowing which libraries you link to will probably not be as useful as you may think, because obviously the symbol is missing from those libraries, however you can use the
-print-file-name=libraryoption to find out which path gcc would use to link a library, example:Also passing
--traceto the linker shows a similar output(Note in the above that
--traceis an argument to the linker so it goes in-Wl.gccinvoked for linking won’t emit anything useful for--traceas an argument togccits self).You could also use
lddafter you successfully build the program to find out which dynamically linked libraries were used, its output looks like this: