[ITK-users] Undefined references to methods of template classes

Matt McCormick matt.mccormick at kitware.com
Sat Jan 10 16:38:32 EST 2015


Hi Francisco,

Nice to hear about the progress!

You will need to link your library to the ITK libraries:

  target_link_libraries( mylibrary ${ITK_LIBRARIES} )

HTH,
Matt

On Sat, Jan 10, 2015 at 4:16 PM, Francisco Lopez de la Franca <
franciscolopezdelafranca at gmail.com> wrote:

> Thanks to your previous answer the problem was solved, but another one has
> come out. It occurs when linking to create the library. It gives an
> undefined reference to itk::ExceptionObject::ExceptionObject... as you can
> see below.
> What it is strange to me is that before including explicit template
> instantiation, I created the library without errors, and now that I include
> that, I get this error.
> I'll appreciate very much any help.
>
> Linking CXX shared library libTFM_Features.dll
>
> CMakeFiles\TFM_Features.dir/objects.a(TFM_Features.cpp.obj):TFM_Features.cpp:(.t
>
> ext$_ZN3itk21MemoryAllocationErrorC1ERKSsjS2_S2_[_ZN3itk21MemoryAllocationErrorC
> 1ERKSsjS2_S2_]+0x35): undefined reference to
> `itk::ExceptionObject::ExceptionObj
> ect(std::string const&, unsigned int, std::string const&, std::string
> const&)'
>
> CMakeFiles\TFM_Features.dir/objects.a(TFM_Features.cpp.obj):TFM_Features.cpp:(.t
>
> ext$_ZN3itk21MemoryAllocationErrorC1ERKSsjS2_S2_[_ZN3itk21MemoryAllocationErrorC
> 1ERKSsjS2_S2_]+0x40): undefined reference to `vtable for
> itk::MemoryAllocationEr
> ror'
>
> C:/CV/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.2/../../../../x86_64-w64-min
> gw32/bin/ld.exe:
> CMakeFiles\TFM_Features.dir/objects.a(TFM_Features.cpp.obj): ba
> d reloc address 0x40 in section
> `.text$_ZN3itk21MemoryAllocationErrorC1ERKSsjS2_
> S2_[_ZN3itk21MemoryAllocationErrorC1ERKSsjS2_S2_]'
> collect2.exe: error: ld returned 1 exit status
> SRC\CMakeFiles\TFM_Features.dir\build.make:219: recipe for target
> 'SRC/libTFM_Fe
> atures.dll' failed
> mingw32-make[2]: *** [SRC/libTFM_Features.dll] Error 1
> CMakeFiles\Makefile2:77: recipe for target
> 'SRC/CMakeFiles/TFM_Features.dir/all'
>  failed
> mingw32-make[1]: *** [SRC/CMakeFiles/TFM_Features.dir/all] Error 2
> Makefile:74: recipe for target 'all' failed
> mingw32-make: *** [all] Error 2
>
>
> 2015-01-09 21:02 GMT+01:00 Matt McCormick <matt.mccormick at kitware.com>:
>
>> Hi Francisco,
>>
>> In order for the templates to be available in the library, they must
>> be explicitly instantiated [1].
>>
>> HTH,
>> Matt
>>
>> [1] http://www.cplusplus.com/articles/1C75fSEw/
>>
>> On Fri, Jan 9, 2015 at 2:59 PM, Francisco Lopez de la Franca
>> <franciscolopezdelafranca at gmail.com> wrote:
>> > Hi.
>> > I' like to create a library containing, for example, one template class
>> with
>> > a number of methods.
>> > I've programmed a simple example and the compilation and generation of
>> the
>> > library goes fine. I use the cmake "add_library" command for generating
>> the
>> > library.
>> >
>> > The problem arises at the moment of testing the library. I get an
>> undefined
>> > reference for every method in the template class.
>> >
>> > I've downloaded a tool to look in the contents (functions) of dynamic
>> > libraries, and there is no function in the library. If I add another
>> class
>> > (not a template class), then, this tool shows me only the functions in
>> this
>> > latter class.
>> >
>> > Has anyone ever come across with this problem?
>> >
>> > Thanks a lot in advance.
>> > Regards
>> > /Francisco
>> >
>> > _____________________________________
>> > 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://public.kitware.com/mailman/listinfo/insight-users
>> >
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20150110/f2ba4ee6/attachment.html>


More information about the Insight-users mailing list