views:

166

answers:

2

Hello everyone,

Under Solaris 10, I'm creating a library A.so that calls a function f() which is defined in library B.so. To compile the library A.so, I declare in my code f() as extern.

Unfortunately, I "forgot" to declare in A's makefile that it has to link with B. However, "make A" causes no warning, no error, and the library A.so is created.

Of course, when executing A's code, the call of f() crashes because it is undefined.

Is there a way (linker option, code trick...) to make the compilation of library A fail ? How can I be sure that all symbols refered to in library A are defined at compile time ?

Thanks for any suggestions.

+1  A: 

Simplest way: add a "test_lib" target in the makefile, that will produce a binary using all the symbols expored from libraryA. (doesn't have to be anything meaningful... just take the address, no need to call the function or anything, it just needs to be referenced).

Virgil
A: 

Tanks

I think I found something interesting and even simpler in the linker's manual (d'ho)

"The -z defs option and the --no-undefined option force a fatal error if any undefined symbols remain at the end of the link. This mode is the default when an executable is built. For historic reasons, this mode is not the default when building a shared object. Use of the -z defs option is recommended, as this mode assures the object being built is self-contained. A self-contained object has all symbolic references resolved internally, or to the object's immediate dependencies."

Simon
1rst answer inhttp://stackoverflow.com/questions/1617286/easy-check-for-unresolved-symbols-in-shared-librariesis actually what I was looking for.
Simon