[vtk-developers] FW: Recent problem with vtk and gcc - repeat
Lorensen, William E (CRD)
lorensen at crd.ge.com
Mon Jan 7 16:33:37 EST 2002
Brad fixed the problem. It was with cmake.
From: Brad King [mailto:brad.king at kitware.com]
Sent: Monday, January 07, 2002 2:02 PM
To: Lorensen, William E (CRD)
Subject: RE: Recent problem with vtk and gcc - repeat
> That fixed it.
> Can you explain?
C++, static data, constructors, and linkers must be used very carefully
together. The old "-Wl,-G" option tells GCC to pass "-G" to the linker.
This tells the linker to create shared libraries. However, it does not
tell g++ itself that a shared library will be built. The result is that
.o files are linked into the shared library without the proper static data
The new "-shared" option tells g++ to build a shared library. It then
knows to generate the proper static data initialization code, and to
automatically pass the -G option to the linker when it invokes it behind
the scenes. This results in the correct behavior. The story isn't over,
however. While this works fine on Linux, the SunOS C++ standard library
does not provide a shared version. This means that one can't link it into
a shared library because each shared library will have its own copy of the
C++ library. Instead, the "-nostdlib" option tells g++ to not link the
standard library into the shared library. Since shared libraries in unix
don't need all the symbols resolved at link-time, this is not a problem.
The executable that loads the shared library will have its own copy of the
static C++ library. This will provide the symbols needed by the loaded
shared library. Therefore, the full set of options needed are "-shared
-nostdlib" to create a shared library on SunOS 5.
The choice of the -Wl,-G option was made by someone in CMake (Amitha, I
think) who was trying to get around the c++ standard library problem with
-shared and didn't know about the -nostdlib flag. I just had Bill Hoffman
commit a fix to cmake to choose this option automatically. It shouldn't
be a problem in the future.
More information about the vtk-developers