[Insight-users] Linking problem when using itk

Andreas Schuh andreas.schuh.84 at googlemail.com
Sat Feb 14 07:27:35 EST 2009


Hi,

first of all I would use the CMake variable ITK_LIBRARIES instead of  
specifying the different libs explicitly. This variable is set by the  
ITK use file, you're including. So,

TARGET_LINK_LIBRARIES(test ${ITK_LIBRARIES})

As your importITK class is a template class, the definitions have to  
be included as well whereever you use a specific instantiation of that  
template class. Therefore, the definitions are usually in a file with  
the extension txx to make clear that it contains template definitions  
only. It makes no sense to compile this file as long as it doesn't  
contain any explicit instantiations. These are usually placed in a  
corresponding cpp file. The txx file is commonly included at the  
bottom of the header file that contains the declaration of your  
templated class. Have a look at some of the ITK classes and you'll  
notice what I mean.

regards
Andreas

Am 13.02.2009 um 20:22 schrieb 李健 <rongx2 at live.cn>:

> Dear all:
>
> I wrote a class to implement some member functions of itk using  
> Linux. The class declaration is in a flie named by importITK.h, and  
> the class definition is in a file named by importITK.cpp. And I  
> wrote a fuction main() in a file named by test.cxx to invoke that  
> class. I included all needed header files in three files. But  
> something's wrong during liking in main() function: undefined  
> reference to member functions of the class I created.
>
> Here is my CMakeLists.txt:
>
> FIND_PACKAGE(ITK)
> IF(ITK_FOUND)
>   INCLUDE(${ITK_USE_FILE})
> ELSE(ITK_FOUND)
>   MESSAGE(FATAL_ERROR
>           "ITK not found. Please set ITK_DIR.")
> ENDIF(ITK_FOUND)
> ADD_EXECUTABLE(test test.cxx importITK.cpp)
> TARGET_LINK_LIBRARIES(test ITKCommon ITKBasicFilters ITKIO)
>
>
> I think maybe something's wrong about the CmakeLists.txt I wrote.
>
> Thanks a lot.
>
> MSN 9.0 正式版上线,捆绑免费25G网络硬盘! 立刻下 
> 载!
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090214/d1df7ca3/attachment-0001.htm>


More information about the Insight-users mailing list