Test for undefined external links on Linux

Is there a linux built-in utility that I can use to test a recently compiled shared library for external links undefined? Gcc seems smart enough to check for undefined characters in my own binary format, but if the character is a link to another library, gcc does not check the link time. Instead, I receive a message only when I try to link my new library to another program.

It seems a bit silly to get undefined help messages in the library when I compile another project, so I want to know if I can check all the links inside and outside when creating the library, not when I link to it.

Error example:

make -C  UnitTests debug
make[1]: Entering directory `~/projects/Foo/UnitTests`
g++ [ tons of objects ] -L../libbar/bin -lbar -o UnitTests
libbar.so: undefined reference to `DoSomethingFromAnotherLibrary`
collect2: ld returned 1 exit status
make[1]: *** [~/projects/Foo/UnitTests] Error 1
+5
source share
1 answer

Normally, undefined links are allowed when linking shared objects, but you can cause the linker to generate an error if the object files you link to create a shared library have undefined characters, delivering them -z defsto the linker (or equivalently -Wl,-z,defsin the gcc command that invokes the linker).

+2
source

All Articles