[CMake] static library linking

Alan W. Irwin irwin at beluga.phys.uvic.ca
Sun Jun 15 12:14:00 EDT 2008


On 2008-06-15 11:47+0200 Steven Van Ingelgem wrote:

> A small example (and verified on a clean SUSE installation):
>
> ====================
> PROJECT(test)
>
> cmake_policy(SET CMP0003 NEW)
>
> ADD_EXECUTABLE(
>  test
>  main.cpp
> )
> TARGET_LINK_LIBRARIES(
>  test
>  /usr/lib/libpthread.a
>  /usr/lib/librt.a
>  /usr/lib/libc.a
> )
> ====================
>
> ==> this won't set the .a's in the commandline as it should do, but rather
> link it via -Wl,-Bstatic...
>
>
> And I really need those static links, because no single other library on the
> system exports the required symbols, not even the shared ones.

Out of curiosity, why doesn't -Wl,-Bstatic -lpthread do exactly what you
want? According to the Linux ld man page, -Bstatic means "do not link
against shared libraries" so shouldn't that have the identical result as
specifying /usr/lib/libpthread.a?

To double-check what is happening with the linking, use "ldd -r" to list
all the shared (but not static) libraries being linked to by test and to
show any symbols which are not resolved by the link.  You can also use
nm to look for unresolved symbols.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list