[Insight-users] compiler error with watershed class : LINK error

Luis Ibanez luis.ibanez at kitware.com
Sun, 07 Mar 2004 08:28:10 -0500


Hi Rodrigo,

It seems that you are missing the "ITKAlgorithms"
library in your TARGET_LINK_LIBRARIES() command.

The WatershedImageFilter is located in

          Insight/Code/Algorithms

therefore its code is compiled in the library
"ITKAlgorithms".

Your CMakeLists.txt file should have lines like:

   ADD_EXECUTABLE(watershed_seg watershed_segmentation.cpp )

   TARGET_LINK_LIBRARIES(watershed_seg
    ITKAlgorithems ITKCommon ITKBasicFilters ITKIO)




Regards,


    Luis


-----------------------
Rodrigo Vivanco wrote:

> Hello,
> 
> I've successfully installed and started to use ITK on Linux running release 9
> (Shrike).
> 
> the example, WatershedSegmentation1.cxx compiles ok.
> 
> 
> I've managed to write small test programs for reading/writing image files,
> anisotrophic filter, GradiantMagnitude using the following CMakeList.txt:
> 
> # This project is designed to be built outside the Insight source tree.
> PROJECT(test_itk)
> 
> # Find ITK.
> FIND_PACKAGE(ITK)
> IF(ITK_FOUND)
>   INCLUDE(${ITK_USE_FILE})
> ELSE(ITK_FOUND)
>   MESSAGE(FATAL_ERROR
>           "Cannot build without ITK.  Please set ITK_DIR.")
> ENDIF(ITK_FOUND)
> 
> ADD_EXECUTABLE(read_write_image read_write_raw_image.cpp )
> TARGET_LINK_LIBRARIES(read_write_image ITKCommon ITKIO)
> 
> ADD_EXECUTABLE(aniso_filter anisotropic_diffusion_filter.cpp )
> TARGET_LINK_LIBRARIES(aniso_filter ITKCommon ITKBasicFilters ITKIO)
> 
> ADD_EXECUTABLE(gradiant_mag_filter gradiant_mag_filter.cpp )
> TARGET_LINK_LIBRARIES(gradiant_mag_filter ITKCommon ITKBasicFilters ITKIO)
> 
> ADD_EXECUTABLE(watershed_seg watershed_segmentation.cpp )
> TARGET_LINK_LIBRARIES(watershed_seg ITKCommon ITKBasicFilters ITKIO)
> 
> 
> however, the following watershed test program fails to compile:
> 
> 
> error:
> 
> Building dependencies cmake.check_depends...
> Building object file watershed_segmentation.o...
> Building executable /home/vivanco/itk/test_itk/watershed_seg...
> watershed_segmentation.o(.gnu.linkonce.t._ZN3itk20WatershedImageFilterINS_5ImageIfLj2EEEE12GenerateDataEv+0x19f):
> In function `itk::WatershedImageFilter<itk::Image<float, (unsigned)2>
> 
>>::GenerateData()':
> 
> : undefined reference to `typeinfo for itk::WatershedMiniPipelineProgressCommand'
> watershed_segmentation.o(.gnu.linkonce.t._ZN3itk36WatershedMiniPipelineProgressCommandC1Ev+0x19):
> In function
> `itk::WatershedMiniPipelineProgressCommand::WatershedMiniPipelineProgressCommand[in-charge]()':
> : undefined reference to `vtable for itk::WatershedMiniPipelineProgressCommand'
> watershed_segmentation.o(.gnu.linkonce.t._ZN3itk13ObjectFactoryINS_36WatershedMiniPipelineProgressCommandEE6CreateEv+0x11):
> In function
> `itk::ObjectFactory<itk::WatershedMiniPipelineProgressCommand>::Create()':
> : undefined reference to `typeinfo for itk::WatershedMiniPipelineProgressCommand'
> watershed_segmentation.o(.gnu.linkonce.t._ZN3itk13ObjectFactoryINS_36WatershedMiniPipelineProgressCommandEE6CreateEv+0x51):
> In function
> `itk::ObjectFactory<itk::WatershedMiniPipelineProgressCommand>::Create()':
> : undefined reference to `typeinfo for itk::WatershedMiniPipelineProgressCommand'
> collect2: ld returned 1 exit status
> make[1]: *** [/home/vivanco/itk/test_itk/watershed_seg] Error 1
> make: *** [default_target] Error 2
> 
> 
> source:
> 
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkWatershedImageFilter.h" 
> 
> 
> int main( int argc, char ** argv )
> {
>   if (argc < 5 )
>     {
>     std::cerr << "Missing Parameters " << std::endl;
>     std::cerr << "Usage: " << argv[0] << " inputImage outputImage level
> threshold" << std::endl;
>     return 1;
>     }
>     
>   typedef itk::Image< float, 2 > ImageType;
>   typedef itk::Image< unsigned long, 2 > SegmentImageType;
> 
>   ImageType::Pointer image_in;
>   SegmentImageType::Pointer seg_image_out;
> 
>   // read input file
>   typedef itk::ImageFileReader< ImageType >  ReaderType;
>   ReaderType::Pointer reader = ReaderType::New();
>   
>   try {
>     reader->SetFileName( argv[1] );
>     std::cerr << "reading file: " << argv[1] << '\n';
>     reader->Update(); // read the data
>   }
>   catch( itk::ExceptionObject & excp ) {
>     std::cerr << "Problem reading data " << std::endl;
>     std::cerr << excp << std::endl;
>     return 1;
>   }
> 
>   image_in = reader->GetOutput();  // get smart-pointer to Image
> 
>   // segment the image
>   typedef itk::WatershedImageFilter<ImageType> WatershedFilterType;
>   WatershedFilterType::Pointer watershed = WatershedFilterType::New();
> /*
>   watershed->SetLevel( atof(argv[2]) );
>   watershed->SetThreshold( atof(argv[3]) );
>   
>   watershed->SetInput(image_in);
>   watershed->Update();
> 
>   seg_image_out = watershed->GetOutput();
> */
>   // write out segmented data
>   typedef itk::ImageFileWriter< SegmentImageType >  WriterType;
>   WriterType::Pointer writer = WriterType::New();
>   try {
>     std::cerr << "writing file: " << argv[4] << '\n';
>     writer->SetFileName( argv[4] );
>     writer->SetInput(seg_image_out);
>     writer->Update(); // write the data
>   }
>   catch( itk::ExceptionObject & excp ) {
>     std::cerr << "Problem writing data " << std::endl;
>     std::cerr << excp << std::endl;
>     return 1;
>   }
>   
>   return 0;
> }
> 
> 
> any suggestions as to why the example code compiles, but this simple test code
> does not...
> 
> thanks,
> 
> Rodrigo
> 
> -------------------------------------------------
> This mail sent through IMP: http://horde.org/imp/
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>