Reputation: 2653
I'm debugging some linker issues ("undefined reference" to symbols that are supposed to be in a library that I'm linking with), and I'm not sure whether the compiler is using the right shared library.
The output I'm looking for is like the one produced by ldd
, that is, a list of libraries with full paths... but I can't use ldd as the compilation fails before producing any output.
The closest I have so far is dumping the library search path and checking the directories one by one for the shared lib in question; I was wondering whether it was a better way of doing this?
Upvotes: 3
Views: 674
Reputation: 3586
You can use gcc -v
verbose flag to make gcc spit out every thing it is doing while compiling and linking your code.
It will show you the path of the actual libraries where the linker search them and flags it is using to compile your code.
Upvotes: 0
Reputation: 213957
I'm debugging some linker issues
You would get much better answers if you show the actual error and the link command line you used.
Most likely you did something like this:
gcc -lfoo main.c
where libfoo.so
is the library that defines the necessary symbol. Read this to understand why above command line is wrong.
but I can't use ldd as the compilation fails before producing any output
Your earlier statement said that your link stage fails. Compilation and linking are not the same thing, please don't mix them up.
I was wondering whether it was a better way of doing this
To find out which libraries the linker is using, read man ld
. On a UNIX system, this command is likely to provide a better way:
gcc ... -Wl,-t
P.S. Also note that there is no such thing as "gcc linker" -- they are completely distinct tools.
Upvotes: 3