[CMake] Creating static executables

Nikita V. Borodikhin nikita at pictures.uniqueics.com.ru
Sat Jun 9 02:22:38 EDT 2007


Alan W. Irwin wrote:
> 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)
> 

There could be two reasons:
1. You have only dynamic libraries
2. CMake use dynamic libraries when building makefile

You can check second one by using CMAKE_VERBOSE_MAKEFILE CMake variable
and check the output while building your project.

> 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.

They _were_ possible but on cmake >= 2.4.4 they are no longer possible
without setting some variables in CMakeLists.txt (not command line!).

Details: http://www.cmake.org/Bug/bug.php?op=show&bugid=5087&pos=13

> 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.)

Yes, first of all linker flags in generated build.make file should be
checked.

> 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.

-- 
Nikita V. Borodikhin, NIKB-RIPN BNV7-RIPE
Registered Linux user #256562 with the Linux Counter
uniqueics.com.ru


More information about the CMake mailing list