[CMake] statically linked executables

Alan W. Irwin irwin at beluga.phys.uvic.ca
Wed Nov 28 17:44:15 EST 2007


On 2007-11-28 21:57-0000 Daniel Rueckert wrote:

> Bill Hoffman wrote:
>> Daniel Rueckert wrote:
>>> Hi,
>>> 
>>> I am trying to build some statically linked executables on a linux
>>> box. I have added the "-static" option to the linker flags and specified
>>> static link libraries but for some reason cmake still adds the option
>>> "-Wl,-Bdynamic" flag to the linker options. Is there any way around 
>>> this?
>>> 
>>> Thanks, Daniel
>> 
>> Sounds like you might have some explicit shared libraries linked into you 
>> project with full paths.
>> 
>> -Bill
>> 
>
> Not explicitly. The shared libraries are -lSM, -lICE (part of X11 I believe)
> and -lm. I have not found any way how to change them into static libraries
> in cmake. I have attached the linking command generated by cmake:
>
> /usr/bin/c++    -fno-const-strings -ffloat-store -Wall -O2  -fPIC -static 
> "CMakeFiles/binarize.dir/binarize.o"   -o ../bin/binarize -rdynamic 
> -L/vol/vipdata/project/linux-ubuntu-static/lib 
> -L/vol/vipdata/packages/Mesa-6.5/lib -Wl,-Bstatic -lz -lfltk_images -lfltk 
> -lfltk_gl -lfltk_forms -Wl,-Bdynamic -lSM -lICE -Wl,-Bstatic -lX11 -lXext 
> -Wl,-Bdynamic -lm -Wl,-Bstatic -lglut -lXmu -lXi -lGLU -lGL -Wl,-Bdynamic 
> -lSM -lICE -Wl,-Bstatic -lX11 -lXext -lznz -lniftiio -lsegmentation++ 
> -lregistration++ -ltransformation++ -lcontrib++ -limage++ -lgeometry++ 
> -lcommon++ -lrecipes -lcontrib++ -limage++ -lgeometry++ -lcommon++ -lrecipes 
> -ltransformation++ -lregistration++ -lsegmentation++ -lniftiio -lznz -lz 
> -lfltk_images -lfltk -lfltk_gl -lfltk_forms -Wl,-Bdynamic -lSM -lICE 
> -Wl,-Bstatic -lX11 -lXext -Wl,-Bdynamic -lm -Wl,-Bstatic -lglut -lXmu -lXi 
> -lGLU -lGL -Wl,-Bdynamic -lSM -lICE -Wl,-Bstatic -lX11 -lXext -Wl,-Bdynamic 
> -Wl,-rpath,/vol/vipdata/project/linux-ubuntu-static/lib:/vol/vipdata/packages/Mesa-6.5/lib
>
> I would be grateful for any suggestions.

Are you sure you have static versions of all your external libraries
(including libSM, libICE and libm) installed?  Sometimes, the static
versions of libraries come in separate developmental packages than the
shared versions for Linux so there may be some additional installation you
have to do to get the static versions.

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