Subject: CGAL users discussion list
List archive
- From: Qianqian Fang <>
- To:
- Subject: Re: [cgal-discuss] Re: link static
- Date: Mon, 25 Apr 2011 16:17:56 -0400
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=Ap3+wKXG6WMH9kx9kBxTQKU3UYEY1/fN65O4GHICiPmIM54afv8zIgs0N3DxWjwhzU myG6fOV3tspYEHD4Q+EIGrjSmLxbAg77o+waozmRyhOtNA4UXQpvf3rbbNfGK9WbPgLB wNge8/kU9N5Cp4YEWehHctUz9D7sRRMWbXXvk=
I have some experience making statically linked binaries, with the help from the list
a few years back (see https://lists-sop.inria.fr/sympa/arc/cgal-discuss/2008-03/msg00168.html )
here is what I do in general:
first, install all the needed libraries, this is quite straightforward in Ubuntu
second, inside the CGAL source folder, run a script with the following command:
#!/bin/sh
cmake . -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=FALSE \
-DMPFR_LIBRARIES=/usr/lib/libmpfr.a -DMPFR_INCLUDE_DIR=/usr/include \
-DGMP_LIBRARIES="/usr/lib/libgmp.a" -DGMPXX_LIBRARIES=/usr/lib/libgmpxx.a -DMPFR_LIBRARY_DIR=/usr/lib \
-DGMP_LIBRARY_DIR=/usr/lib -DGMP_INCLUDE_DIR=/usr/include -DOPENGL_INCLUDE_DIR=/usr/X11R6/include \
-DWITH_examples=true -DCGAL_CXX_FLAGS="-I/usr/include -L/usr/lib" -DBoost_LIBRARYDIR=/usr/lib \
-DBoost_LIBRARIES=/usr/lib/libboost_thread.a
Certainly, make sure all the *.a files exist on your system. Then do a "make", this will
generate all static CGAL library files. Now navigate into the example or your project
folder, do
make program_name VERBOSE=1
where program_name is the file name (without .cpp) of the example unit. This will
compile and link the program (dynamically). When it completes, copy the linking
command to a text editor, and modify it in the following ways:
1. insert flag "-static-libgcc" right after c++,
2. delete anything following -Wl,-Bdynamic, you will notice there are typically several repetitions of the library names
3. when removing all the dynamic libraries, you need to append "-lpthread", sometimes "-lz" at the end
run the modified command will generate a statically linked binary. If anything missing,
try to append the library name to the command line.
In my specific application, I don't need visualization, however, linking against ImageIO introduces
OpenGL and Xlib dependencies and makes static linking difficult. I edit the Image_3.cpp unit
and comment out two functions involving OpenGL calls. This allows you to drop all the GL related
libraries in the linking stage.
Let me know if this helps.
Qianqian
On Mon, Apr 25, 2011 at 7:57 AM, pascal8361 <> wrote:
I tried some of that ... but with no great success ...
Below is the original link command with static qt libraries ...
I tried to do - as you did in your example, ant that is my new link command
(in comparison to the one below) (When linking with this one the file gets a
little smaller - around 500 kb.):
/usr/bin/c++ -frounding-math -g -Wl
CMakeFiles/Pseudo_triangulation_2.dir/src/Pseudo_triangulation_2.o
CMakeFiles/Pseudo_triangulation_2.dir/qrc_Pseudo_triangulation_2.o -o
Pseudo_triangulation_2 -Bstatic -L/usr/local/lib
/usr/local/lib/libCGAL_Qt4.a /usr/local/lib/libCGAL.a -Wl,-Bstatic
-lboost_thread-mt -Wl,-Bstatic
/usr/local/Trolltech/Qt-4.7.0/lib/libQtOpenGL.a -Wl,-Bstatic -lGLU
-Wl,-Bdynamic -lGL -Bstatic /usr/local/Trolltech/Qt-4.7.0/lib/libQtGui.a
-Wl,-Bstatic -lpng -lSM -lICE -lXrender -lfreetype -Wl,-Bdynamic
-lfontconfig -Wl,-Bstatic -lXext -lX11 -Wl,-Bstatic
/usr/local/Trolltech/Qt-4.7.0/lib/libQtCore.a -Wl,-Bstatic
/usr/local/Trolltech/Qt-4.7.0/lib/libQtCore.a -Wl,-Bdynamic
There are a couple of questions:
1. Is it right to (only) deal with the command under: "Linking CXX
executable Pseudo_triangulation_2", or can there be any dependencies with
the other files/commands? (I don't think so as they are qt specific, is this
right?)
2. Is there a way to see which libraries cause the dynamic linkages? Or is
it just the dynamic link with lGL (I think this will be OPENGL) and
fontconfig? What does the last -Wl, -Bdynamic mean (this is necessary - it
is not working without this)?
3. And the most important question: Does anyone see a way around these
dependencies? :-)
Best
Pascal
- [cgal-discuss] link static, pascal8361, 04/17/2011
- Re: [cgal-discuss] link static, Joachim Reichel, 04/20/2011
- [cgal-discuss] Re: link static, pascal8361, 04/20/2011
- [cgal-discuss] Re: link static, pascal8361, 04/20/2011
- Re: [cgal-discuss] Re: link static, Joachim Reichel, 04/24/2011
- [cgal-discuss] Re: link static, pascal8361, 04/24/2011
- [cgal-discuss] Re: link static, pascal8361, 04/25/2011
- Re: [cgal-discuss] Re: link static, Joachim Reichel, 04/25/2011
- Re: [cgal-discuss] Re: link static, Qianqian Fang, 04/25/2011
- [cgal-discuss] Re: link static, pascal8361, 04/25/2011
- [cgal-discuss] Re: link static, pascal8361, 04/24/2011
- Re: [cgal-discuss] Re: link static, Joachim Reichel, 04/24/2011
- [cgal-discuss] Re: link static, pascal8361, 04/20/2011
- [cgal-discuss] Re: link static, pascal8361, 04/20/2011
- Re: [cgal-discuss] link static, Joachim Reichel, 04/20/2011
Archive powered by MHonArc 2.6.16.