I have a program foothat can load plugins through dlopen(). I am writing one such plugin foobarthat interacts with the functionality provided by a third-party library libfoo.
On Linux, I create foobaras follows:
gcc -fpic -c -o foobar.o foobar.c
gcc -fpic -shared -o foobar.so foobar.o -lbar
So far so good.
The problem is that it does not detect undefined characters, for example, due to errors in the code or inconsistencies between the header files and the library. The link succeeds, and you get an error later when you load the plugin or when you call something in the plugin (depending on the flags dlopen()).
To detect undefined characters in a shared library, is usually used -Wl,-z,defsor, perhaps -Wl,--no-allow-shlib-undefined. But this will not succeed, since it will also report characters that must be found in the program fooat runtime. I would like to detect undefined characters, other than those provided by the hosting program.
In Mac OS X, for example, this is done using an option -bundle_loader. Equivalent link will be
gcc -bundle -o foobar.so foobar.o -lbar -bundle_loader=foo
and which detects undefined characters the way I want.
How to do it on GNU / Linux or generally with GNU ld? (I looked through all the options listed on the ldman page , but no one looked promising.)
source
share