[CMake] building static binaries
loose at astron.nl
Thu Nov 4 04:35:49 EDT 2010
On Wed, 2010-11-03 at 17:57 +0100, Michael Hertling wrote:
> On 11/02/2010 10:54 PM, Szilárd Páll wrote:
> > Hi,
> > I've been trying to implement a feature which would enable building
> > static binaries with cmake, but I've got completely stuck, I hope
> > someone can hint me what's the best way to do this.
> > What I've done is a 2 stage solution for making static binaries:
> > 1) Telling cmake to prefer picking up ".a"-s when searching for
> > libraries (CMAKE_FIND_LIBRARY_SUFFIXES).
> > This works fine, but referring to file extensions/endings might not be
> > general enough. Making it less platform-dependent would require
> > rewriting the way external libraries are treated: instead of adding
> > them with full path we'd need to add -Lpath -llibname separately. Any
> > other ways for doing this?
> > 2) Telling cmake to use static system libraries.
> > This should work with the target property LINK_SEARCH_END_STATIC which
> > essentially should result in a the system libs linked in statically
> > whenever possible (depending on the platform). Well, it seems that
> > even in fairly straightforward situations (Linux + gcc) I get the a
> > linker error: /usr/bin/ld: cannot find -lgcc_s.
> > Obviously, libgcc_s.a is not available, but by looking at the verbose
> > output, the implicit gcc linker call contains the "-Wl,-Bstatic"
> > argument. This AFAIK is not correct, or more precisely not enough to
> > just tell ld to link statically, gcc also has to know about it
> > (through the "-static" argument). Can anyone confirm this?
> > I'd be grateful for tips on how to fix the issue with 2), but I'm open
> > for other portable (and preferably elegant) solutions.
> FYI: See , and in particular  and .
>  http://email@example.com/msg21106.html
>  http://firstname.lastname@example.org/msg21317.html
>  http://email@example.com/msg21416.html
> Powered by www.kitware.com
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> Follow this link to subscribe/unsubscribe:
You may also want to read
More information about the CMake