[vtkusers] static libs...

Obada Mahdi omahdi at gmx.de
Tue Oct 17 18:38:28 EDT 2006


Hi Frederic,

On 10/17/06, fred <fredmfp at gmail.com> wrote:
> I need to use VTK libs in static (so I rebuilt VTK with them).
>
> I have no problem with shared libs:
>
> gcc -Wall vtktest.c -lvtkIO -o vtktest"
>
> works fine, no warning, no error message.
>
> But with -static:
>
> gcc -Wall -static vtktest.c -lvtkIO -o vtktest"
>
> I have a lot of error messages:
[...]

actually, I am surprised that your first command should work--is there
any C++ code in "vtktest.c"?  I would not know of a gcc that accepts
C++ code unless the source file has a "proper" extension (like "cc",
"cxx"...), or it is explicitly stated on the command line.

Anyway, you should invoke the compiler via "g++" (or "c++") instead of
"gcc" for C++ projects, because that will not only treat your code as
C++ by default, but also add some stuff in the linking stage, which is
not the case for "gcc" (like "libstdc++", which has the
"std::ios_base" symbols mentioned in your error log):

> /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libvtkIO.a(vtkXMLWriterC.o):
> In function `__static
> _initialization_and_destruction_0(int, int)':
> vtkXMLWriterC.cxx:(.text+0x23): undefined reference to
> `std::ios_base::Init::Init()'

Unlike shared libraries, static libraries do not carry dependency
information, so every required library needs to be stated explicitly
(in order, which means that a library is to be given on the command
line after the one that depends on it).  You can obtain dependency
information from
"<PREFIX>/lib/vtk-<VERSION>/VTKLibraryDepends.cmake",
or, better yet, use CMake to build your project--just have a look at
one of the "CMakeLists.txt" files from the VTK C++ examples.

HTH,

Obada



More information about the vtkusers mailing list