[Insight-users] [Insight-Developers] Problem with trivial filter (no inputs and outputs)

Alessio Mazzarini alessiomazzarini89 at gmail.com
Thu Jan 23 11:56:56 EST 2014


Hi all. I'm trying to create a very simple filter with no inputs and 
outputs and templates but when i make it, compilers gives me some errors 
and i don't understand how to fix them.

this is my header file of the filter:
****************TrainingFilter.h******************
#ifndef __TrainingFilter_h
#define __TrainingFilter_h

#include "itkObject.h"
#include "itkImage.h"

namespace itk
{
  class  TrainingFilter :
    public Object
{
     public:
       /** Standard class typedefs. */
   typedef TrainingFilter                                   Self;
   typedef Object Superclass;
   typedef SmartPointer < Self > Pointer;
   typedef SmartPointer < const Self > ConstPointer;

   itkNewMacro (Self);
   itkTypeMacro(TrainingFilter, Object);

   void Update();  //Method of the filter

protected:
   TrainingFilter();
   ~TrainingFilter();

private:
   TrainingFilter(const Self &); //purposely not implemented
   void operator=(const Self &);          //purposely not implemented
   };
}
#endif


This is its implementation:
*******************TrainingFilter.cxx*************
#include "TrainingFilter.h"
#include "itkObject.h"
#include <iostream>

namespace itk
{
TrainingFilter::TrainingFilter()  { };

TrainingFilter::~TrainingFilter()  { };

   void TrainingFilter::Update()
{
std::cout<<"**Filter called .cxx **"<<std::endl;
}
} // end namespace



and this is my main, where i try, as usual, to create a FilterType and a 
smartpointer to call the Update method.
***********main.cxx*****************
#include "TrainingFilter.h"
#include <iostream>
using namespace std;

int main(int argc, char * argv [])
{
   typedef itk::TrainingFilter  FilterTypeTraining;
   FilterTypeTraining::Pointer filterTraining = FilterTypeTraining::New();

   try
     {
     filterTraining-> Update();
     }
   catch( itk::ExceptionObject & excp )
     {
     std::cerr << "Exception caught !" << std::endl;
     std::cerr << excp << std::endl;
     }
   return 0;
}



This is the compiler error:

CMakeFiles/TrainingFilter.dir/main.cxx.o: In function `main':
main.cxx:(.text+0x2c): undefined reference to 
`itk::TrainingFilter::Update()'
CMakeFiles/TrainingFilter.dir/main.cxx.o: In function 
`itk::TrainingFilter::New()':
main.cxx:(.text._ZN3itk14TrainingFilter3NewEv[itk::TrainingFilter::New()]+0x42): 
undefined reference to `itk::TrainingFilter::TrainingFilter()'
CMakeFiles/TrainingFilter.dir/main.cxx.o: In function 
`itk::ObjectFactory<itk::TrainingFilter>::Create()':
main.cxx:(.text._ZN3itk13ObjectFactoryINS_14TrainingFilterEE6CreateEv[itk::ObjectFactory<itk::TrainingFilter>::Create()]+0xe): 
undefined reference to `typeinfo for itk::TrainingFilter'
main.cxx:(.text._ZN3itk13ObjectFactoryINS_14TrainingFilterEE6CreateEv[itk::ObjectFactory<itk::TrainingFilter>::Create()]+0x47): 
undefined reference to `typeinfo for itk::TrainingFilter'
collect2: ld returned 1 exit status
make[2]: *** [TrainingFilter] Error 1
make[1]: *** [CMakeFiles/TrainingFilter.dir/all] Error 2
make: *** [all] Error 2



Thanks for your help,
Alessio



More information about the Insight-users mailing list