[CMake] Creating static executables

Bill Hoffman bill.hoffman at kitware.com
Mon Jun 11 20:19:33 EDT 2007


Ajay Divekar wrote:
> I tried the following in my CMakeLists.txt file.
>
> SET (CMAKE_EXE_LINK_DYNAMIC_C_FLAGS "-Wl,-Bstatic")
> SET_TARGET_PROPERTIES (xxxx PROPERTIES LINK_FLAGS "-L/usr/local/lib/  
> -L/usr/lib")
>
> I have checked that libc.a and libm.a exists in the /usr/lib directory. I am 
> currently using FreeBSD5.5. When I compile and ldd the executable I get
>         libstdc++.so.4 => /usr/lib/libstdc++.so.4 (0x280e6000)
>         libm.so.3 => /lib/libm.so.3 (0x281bc000)
>         libc.so.5 => /lib/libc.so.5 (0x281d7000)
>
>
> If I copy the libc.a and libm.a to another directory say /home/alex/libs and 
> then include 
> SET_TARGET_PROPERTIES (xxxx PROPERTIES LINK_FLAGS "-L/usr/local/lib/  
> -L/home/alex/libs")
>
> The executable created is a purely static executable. I cannot explain this?
>
>
>  ALso when I try to take these sources and compile it on FreeBSD 6.2 using the 
> same Cmake Files I get on doing ldd on the executable
>
> libstdc++.so.6=> /usr/local/lib/gcc/i386-portbld-freebsd6.2/3.4.6/libstdc++.so.6 
> libgcc_s.so.1=> /usr/local/lib/gcc/i386-portbld-freebsd6.2/3.4.6/libgcc_s.so.1       
> libm.so.4 => /lib/libm.so.4 (0x28223000)
> libc.so.6 => /lib/libc.so.6 (0x28239000)
>
> the difference is that gcc is linked as shared library on BSD6.2 whereas on 
> BSD5.5 it was static. Please someone explain. 
>
> Regards,
>
> Ajay
>
>
> BTW I am using CMake 2.4.6
>
>   
Can you run make VERBOSE=1 so we can see the actual command being used 
for the link?

-Bill



More information about the CMake mailing list