[CMake] Linking problem

Juan Sanchez Juan.Sanchez at amd.com
Wed Nov 7 11:23:35 EST 2007


Two things with convenience libraries.  Part of this may be in the FAQ:

On linux, compile the code fPIC or fpic (slightly different meanings).

So for library hello:
SET_TARGET_PROPERTIES(
hello PROPERTIES
OUTPUT_NAME hello
CLEAN_DIRECT_OUTPUT 1
COMPILE_FLAGS -fPIC
)

where hello is the name of your static convenience library.

Make sure all symbols get put into the so:
target_link_libraries(mywrap -Wl,-whole-archive
hello -Wl,-no-whole-archive)

where mywrap is the name of the shared library, and hello is the static
library you want attached to it.  If you are attaching multiple
libraries, linker order may be important.

Juan



Salvatore Iovene wrote:
> Hi,
> I'm not 100% sure this is really a CMake related question, but I'll
> fire it up anyway:
> 
> I'm building a series of static libraries, name them liba.a, libb.a
> and libc.a, and linking them into a shared library libfoo.so.
> 
> Then I'm building libx.a liby.a and libz.a and linking them into the
> shared libbar.so.
> 
> Then I have an executable whatever.exe that's linked to to libfoo.so
> and libbar.so. The linking of the executable fails complaining of
> certain missing simbols. Some symbols from liba.a are missing in
> libbar.so.
> 
> So far I have "fixed" the issue by linking one of the libs of
> libfoo.so (say libx.a) to libbar.so. But this smells of nasy
> workaround.
> 
> Obviously I'm doing something wrong here, so could anyone please help?
> 
> Thanks!
> 


-- 
Juan Sanchez
Juan.Sanchez at amd.com
800-538-8450 Ext. 54395
512-602-4395




More information about the CMake mailing list