[CMake] Creating static executables

Alan W. Irwin irwin at beluga.phys.uvic.ca
Fri Jun 8 17:57:31 EDT 2007


On 2007-06-08 15:37-0400 Ajay Divekar wrote:

> I tried your suggestion by setting
>
> SET_TARGET_PROPERTIES (bbb PROPERTIES LINK_FLAGS "-static -lc -lm
> -L/usr/local/lib/")
>
> The result is the same i.e. the executable generated is not completely static.
> Still has shared library dependencies. The output generated after doing ldd
> bbb is
>
>        libz.so.2 => /lib/libz.so.2 (0x28233000)
>        libm.so.3 => /lib/libm.so.3 (0x28243000)
>        libc.so.5 => /lib/libc.so.5 (0x2825e000)

I frankly don't understand why that failed to work.  Completely static
executables are possible with cmake.  I know this because I made one several
months ago as a temporary experiment.  Look carefully at your make output.
I am virtually positive your link step is missing the -static option for
some reason (or else you have some stale older results interfering; make
sure you start with an empty build tree.)

If after reviewing that evidence, you still cannot figure how to impose the
-static link flag with cmake, I suggest you prepare the simplest possible
(i.e., "hello-world") example (which after all, normally links to libc) and
give us the complete details (CMakeLists.txt, hello-world.c, and complete
cmake and make results) of that example so we can figure out where you are
going wrong.

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