[Insight-users] Link errors with static libs (shared fixes problems!)

Zachary Pincus zpincus at stanford.edu
Wed, 28 Apr 2004 01:39:53 -0700


Hello, and I promise that this is my last plaintive request for 
tonight...

After finally getting ITK updated from the CVS and compiled, I've run 
into strange linker errors when rebuilding my applications. Basically, 
they're complaining that certain symbols are undefined; however I can 
check the libs and verify that they're around.

Here's the really strange part: this only occurs when I'm using the 
static libraries. If I rebuild ITK with the same settings but with 
"build shared libs" set to "ON", and then rebuild my project, 
everything works just fine. I'm using OS X 10.3.3 with gcc 3.3. 
"Explicit Instantiations" are turned off.

Here is the specific error (the Cellxxxx libraries are my own):

Building executable /.../ImageExtractionAndPCATester...
c++        -ftemplate-depth-50 -no-cpp-precomp -Wno-long-double 
-fmessage-length=0 -fPIC  ./ImageExtractionAndPCATester.o    [link 
directories snipped]  -lITKCommon -lITKIO -lCellExplorerCommon 
-lCellExtractor -lCellFeatures -lITKCommon -litkvnl_inst -litkvnl_algo 
-litkvnl -litkvcl -litknetlib -lm -litksys -lpthread -litkpng -litktiff 
-litkjpeg -lm -lITKMetaIO -litkzlib -lITKDICOMParser -lITKEXPAT
ld: Undefined symbols:
itk::ImageIOBase::SetNumberOfDimensions(unsigned)
itk::ImageIOFactory::CreateImageIO(char const*, 
itk::ImageIOFactory::FileModeType)
itk::operator<<(std::basic_ostream<char, std::char_traits<char> >&, 
itk::ImageIORegion const&)
itk::ImageIOBase::GetImageSizeInBytes() const
vtable for itk::ImageIORegion

Why would these symbols be undefined? I can find them in the linked-in 
libraries with nm well enough, and other symbols from the IO and Common 
(and other) libraries are found easily enough. Can anyone provide any 
clues as to where to look to deal with this? Why is this magically 
fixed with the dynamic libs? As usual, the linker is sufficiently 
mysterious to me that I'm not much help.

Thanks,

Zach Pincus

Department of Biochemistry and Program in Biomedical Informatics
Stanford University School of Medicine