Check the linker option -z defs / --no-undefined . When creating a shared object, this will lead to communication failure if there are unresolved characters.
If you use gcc to invoke the linker, you will use the -Wl compiler -Wl to pass the option to the linker:
gcc -shared ... -Wl,-z,defs
As an example, consider the following file:
#include <stdio.h> void forgot_to_define(FILE *fp); void doit(const char *filename) { FILE *fp = fopen(filename, "r"); if (fp != NULL) { forgot_to_define(fp); fclose(fp); } }
Now, if you create this in a shared object, it will succeed:
> gcc -shared -fPIC -o libsilly.so silly.c && echo succeeded || echo failed succeeded
But if you add -z defs , the link will not work and will tell you about your missing character:
> gcc -shared -fPIC -o libsilly.so silly.c -Wl,-z,defs && echo succeeded || echo failed /tmp/cccIwwbn.o: In function `doit': silly.c:(.text+0x2c): undefined reference to `forgot_to_define' collect2: ld returned 1 exit status failed
R Samuel Klatchko Nov 04 '09 at 1:25 2009-11-04 01:25
source share