[vtkusers] Creating a statically linked application

Christopher Bayley bayley at me.queensu.ca
Mon Feb 17 12:47:57 EST 2003


Hello

System: RH Linux 7.1
        VTK4.0
        ldd gnu v2.12
        gcc 2.96

I am trying to statically link the VTK libraries into the binary to use
on computers that don't have VTK installed on them.  However, I still
want to dynamically link other libraries.  I have searched the archives
and not found a satisfactory solution for my problem.  

First, within the directory /usr/local/lib/vtk I ran:

        ar cru libVTKCommon.a libVTKCommon.so etc 

to create static libraries from the shared vtk libraries.

Next I compile all of my individual functions to create object files:
*.o

Finally at link time, I use:

g++  ReadData.o Slopes.o FindHoles.o VTKactors.o markers.o
WeldViewer.o   \
  -g -O2  -L/usr/local/lib/vtk -L/usr/X11R6/lib  \
  -Wl,-rpath,/usr/local/lib/vtk \
  -Wl,-Bstatic -lvtkRendering -lvtkGraphics -lvtkImaging -lvtkIO
-lvtkFiltering -lvtkCommon -lvtkHybrid  \
  -Wl,-Bdynamic -lXm -lGL -lXt  -lSM -lICE -lX11 -lXext -lpthread -ldl
-lm \
  -o WeldViewer 

The key features are '-Wl,-Bstatic' and '-Wl,-Bdynamic' which are
supposed to create either static or dynamic links.  However I check the
application to see what has been linked with ldd and see that:

[cbayley at tremblant WeldView]$ ldd ./WeldViewer
        libvtkRendering.so => /usr/local/lib/vtk/libvtkRendering.so
(0x40018000)
        libvtkGraphics.so => /usr/local/lib/vtk/libvtkGraphics.so
(0x40236000)
        libvtkImaging.so => /usr/local/lib/vtk/libvtkImaging.so
(0x40548000)
        libvtkIO.so => /usr/local/lib/vtk/libvtkIO.so (0x40842000)
        libvtkFiltering.so => /usr/local/lib/vtk/libvtkFiltering.so
(0x40a73000)
        libvtkCommon.so => /usr/local/lib/vtk/libvtkCommon.so
(0x40ae1000)
        libvtkHybrid.so => /usr/local/lib/vtk/libvtkHybrid.so
(0x40cbc000)
        libXm.so.2 => /usr/X11R6/lib/libXm.so.2 (0x40dfd000)
        libGL.so.1 => /usr/lib/libGL.so.1 (0x40f99000)
        libXt.so.6 => /usr/X11R6/lib/libXt.so.6 (0x4116d000)
        libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x411b9000)
        libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x411c2000)
        libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x411da000)
        libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x412d0000)
        libpthread.so.0 => /lib/i686/libpthread.so.0 (0x412de000)
        libdl.so.2 => /lib/libdl.so.2 (0x412f3000)
        libstdc++-libc6.2-2.so.3 => /usr/lib/libstdc++-libc6.2-2.so.3
(0x412f7000)
        libm.so.6 => /lib/i686/libm.so.6 (0x4133a000)
        libc.so.6 => /lib/i686/libc.so.6 (0x4135e000)
        libvtkpng.so => /usr/local/VTK/bin/libvtkpng.so (0x4149a000)
        libvtkzlib.so => /usr/local/VTK/bin/libvtkzlib.so (0x414ba000)
        libvtkjpeg.so => /usr/local/VTK/bin/libvtkjpeg.so (0x414c7000)
        libXp.so.6 => /usr/X11R6/lib/libXp.so.6 (0x414e4000)
        libXmu.so.6 => /usr/X11R6/lib/libXmu.so.6 (0x414ed000)
        libXi.so.6 => /usr/X11R6/lib/libXi.so.6 (0x41503000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

which indicates to me that the shared vtk-libraries are used, not the
static ones as I requested.

What am I doing wrong?

Thanks in advance for your help.  I really appreciate all the help that
I receive


Christopher Bayley



More information about the vtkusers mailing list