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

Matt McCormick matt.mccormick at kitware.com
Thu Jan 23 14:13:12 EST 2014


Hi Alessio,

It looks like your making good progress.

The next step is to inherit from ProcessObject instead of Object to
get the filter pipeline functionality (which may be important
depending on the application).

Regarding the linking error, what does the CMakeLists.txt look like?
Is the file TrainingFilter.cxx (where itk::TrainingFilter::Update() is
defined) built into the executable?

Thanks,
Matt

On Thu, Jan 23, 2014 at 11:56 AM, Alessio Mazzarini
<alessiomazzarini89 at gmail.com> wrote:
> 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
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/cgi-bin/mailman/listinfo/community
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-developers



More information about the Community mailing list