[Insight-users] undefined reference Templated Class

Mark Bouts mark at invivonmr.uu.nl
Thu Sep 6 12:28:05 EDT 2007


Hi Lars,

if it is no problem could you give some more info. Maybe sent me both 
files, then I will take a brief look at it.

Mark



On Thu, 6 Sep 2007, Lars Nygard wrote:

> Hey Mark,
>
> (thanks, should've paid attention when Bram was giving colleges:)
>
>
>
> Ive gotten rid of the shadows error by using #ifndef
> but now I still get an error (see below). Probably something
> to do with the templates cause it works without  templates.
> Error:
> C:\Insight\myPrograms\generateProblems\gradient.cxx:22: error: expected constructor, destructor, or
> type conversion before '<' token
> C:\Insight\myPrograms\generateProblems\gradient.cxx:22: error: expected `;' before '<' token
> C:\Insight\myPrograms\generateProblems\gradient.cxx:52: error: expected init-declarator before '<' t
> oken
> C:\Insight\myPrograms\generateProblems\gradient.cxx:52: error: expected `;' before '<' token
> C:\Insight\myPrograms\generateProblems\gradient.cxx:71: error: expected init-declarator before '<' t
> oken
> C:\Insight\myPrograms\generateProblems\gradient.cxx:71: error: expected `;' before '<' token
> C:\Insight\myPrograms\generateProblems\gradient.cxx:89: error: expected init-declarator before '<' t
> oken
> C:\Insight\myPrograms\generateProblems\gradient.cxx:89: error: expected `;' before '<' token
> mingw32-make[2]: *** [CMakeFiles/generateProblems.dir/gradient.obj] Error 1
> mingw32-make[1]: *** [CMakeFiles/generateProblems.dir/all] Error 2
> mingw32-make: *** [all] Error 2
>
>
>
> ----- Original Message ----
> From: Mark Bouts <mark at invivonmr.uu.nl>
> To: Lars Nygard <lnygard at yahoo.com>
> Sent: Thursday, September 6, 2007 8:55:38 AM
> Subject: Re: [Insight-users] undefined reference Templated Class
>
>
> Hi Lars,
>
> make sure that you don't use a double declaration. This means that you
> must be carefull including both *.h and *.cpp files. Please do make sure
> you have include-guards in your *.h file.
> Ie.
>
> #ifndef GRADIENT_H
> #define GRADIENT_H
>
> /** your code */
>
> #endif /* GRADIENT_H*/
>
> Additionally make sure you don't declare the class gradient in both the
> *.cpp and *.h files.
>
> Hope it helps!
>
> Grtz,
>
> Mark
>
> On Thu, 6 Sep 2007, Lars Nygard wrote:
>
>> Hi Gaetan,
>>
>>
>>
>> Thanks for the help. Ive tried that but than I get the following
>> error:
>>
>> In file included from C:\Insight\myPrograms\generateProblems\/gradient.h:98,
>>                 from C:\Insight\myPrograms\generateProblems\/main.h:18,
>>                 from C:\Insight\myPrograms\generateProblems\main.cxx:13:
>> C:\Insight\myPrograms\generateProblems\/gradient.cxx:18: error: declaration of `class
>> C:\Insight\myPrograms\generateProblems\/gradient.h:20: error:  shadows template parm
>> C:\Insight\myPrograms\generateProblems\/gradient.cxx:20: error: cannot declare member
>> ient<TImage>::gradient' within `gradient<TImage>'
>> C:\Insight\myPrograms\generateProblems\/gradient.cxx:47: error: declaration of `class
>> C:\Insight\myPrograms\generateProblems\/gradient.h:20: error:  shadows template parm
>> C:\Insight\myPrograms\generateProblems\/gradient.cxx:51: error: cannot declare member
>> ient<TImage>::LoadImageA' within `gradient<TImage>'
>> C:\Insight\myPrograms\generateProblems\/gradient.cxx:66: error: declaration of `class
>> C:\Insight\myPrograms\generateProblems\/gradient.h:20: error:  shadows template parm
>> C:\Insight\myPrograms\generateProblems\/gradient.cxx:70: error: cannot declare member
>> ient<TImage>::SaveImage' within `gradient<TImage>'
>> C:\Insight\myPrograms\generateProblems\/gradient.cxx:84: error: declaration of `class
>> C:\Insight\myPrograms\generateProblems\/gradient.h:20: error:  shadows template parm
>> C:\Insight\myPrograms\generateProblems\/gradient.cxx:88: error: cannot declare member
>> ient<TImage>::CompGradient' within `gradient<TImage>'
>> mingw32-make[2]: *** [CMakeFiles/generateProblems.dir/main.obj] Error 1
>> mingw32-make[1]: *** [CMakeFiles/generateProblems.dir/all] Error 2
>> mingw32-make: *** [all] Error 2
>> ----- Original Message ----
>> From: Gaëtan Lehmann <gaetan.lehmann at jouy.inra.fr>
>> To: Lars Nygard <lnygard at yahoo.com>
>> Cc: insight-users at itk.org
>> Sent: Thursday, September 6, 2007 7:37:04 AM
>> Subject: Re: [Insight-users] undefined reference Templated Class
>>
>>
>> Hi Lars,
>>
>> Your gradient class is templated, so you have to include the cxx file
>> at the end of the header to make it work.
>>
>> #include "gradient.cxx"
>>
>> Because of the template, you can't (easily) build the code in
>> your .cxx file and put it in a shared object.
>>
>> Regards,
>>
>> Gaëtan
>>
>>
>>
>>
>> Le 6 sept. 07 à 16:28, Lars Nygard a écrit :
>>
>>> hi everybody,
>>>
>>> Id really appreciate some help with this. I don't know if this has
>>> something to do with ITK or if it's just basic c++. Whenever I try
>>> to make an instance of gradient Im getting an undefined reference
>>> Linker error:
>>>
>>> Linking CXX executable generateProblems.exe
>>> CMakeFiles/generateProblems.dir/main.obj:main.cxx:(.text+0x288):
>>> undefined reference to `gradient<it
>>> k::Image<unsigned short, 3u> >::gradient()'
>>> collect2: ld returned 1 exit status
>>> mingw32-make[2]: *** [generateProblems.exe] Error 1
>>> mingw32-make[1]: *** [CMakeFiles/generateProblems.dir/all] Error 2
>>> mingw32-make: *** [all] Error 2
>>>
>>> Ive attached both .h and cxx class, hope this works.
>>> thanks for any help.
>>> lars
>>>
>>>
>>>
>>>
>>>
>>> _________________________________________________________
>>> Alt i én. Få Yahoo! Mail med adressekartotek, kalender og
>>> notisblokk. http://no.mail.yahoo.com
>>> <gradient.cxx>
>>> <gradient.h>
>>> _______________________________________________
>>> Insight-users mailing list
>>> Insight-users at itk.org
>>> http://www.itk.org/mailman/listinfo/insight-users
>>
>> --
>> Gaëtan Lehmann
>> Biologie du Développement et de la Reproduction
>> INRA de Jouy-en-Josas (France)
>> tel: +33 1 34 65 29 66    fax: 01 34 65 29 09
>> http://voxel.jouy.inra.fr
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> _________________________________________________________
>> Alt i én. Få Yahoo! Mail med adressekartotek, kalender og
>> notisblokk. http://no.mail.yahoo.com
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at itk.org
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>
>
>
>
>
> _________________________________________________________
> Alt i én. Få Yahoo! Mail med adressekartotek, kalender og
> notisblokk. http://no.mail.yahoo.com
>


More information about the Insight-users mailing list