[Insight-users] Multiple symbol definition at linker stage with ITK4

Sergio Vera sergio.vera at alma3d.com
Tue Jun 5 11:11:41 EDT 2012


Hello all,

We are experiencing problems when linking our tests for a simple library
after switching to ITK4.
Our library is a dll. With itk3.20 we used to link it against ITKIO but
following some advices from and is linked with ${ITK_LIBRARIES}.

we have something like this in our testing's CMakeLists.txt:

(...)
# Link the executables to the required libraries.
IF (${ITK_VERSION_MAJOR} GREATER 3)
    SET(MY_ITK_LIBRARIES ${ITK_LIBRARIES})
ELSE ()
    SET(MY_ITK_LIBRARIES ITKIO)
ENDIF ()
(...)

Now, with ITK4 both the library and the test exes link with ${ITK_LIBRARIES}
so the linker complains about redefined symbols:

1>------ Build started: Project: TestAlgorithms, Configuration: Release
Win32 ------
1>  Building Custom Rule C:/cygwin/users/fpcx/soft/Alma-in-server/AuxTools/
AuxITK/AuxITKLib/Testing/CMakeLists.txt
1>  CMake does not need to re-run because C:\users\bin\Alma-in-server\
AuxTools\AuxITK\AuxITKLib\dll\win32-vs10-release-build\
Testing\CMakeFiles\generate.stamp is up-to-date.
1>ITKCommon-4.1.lib(itkDataObject.obj) : error LNK2005: "public: class
itk::ProcessObject * __thiscall itk::SmartPointerForwardReference<class
itk::ProcessObject>::operator->(void)const " (??C?$
SmartPointerForwardReference at VProcessObject@itk@@@itk@@QBEPAVProcessObject at 1@XZ)
already defined in AuxITKLib.lib(AuxITKLib.dll)
1>ITKCommon-4.1.lib(itkDataObject.obj) : error LNK2005: "public: __thiscall
itk::SmartPointerForwardReference<class itk::ProcessObject>::operator class
itk::ProcessObject *(void)const " (??B?$SmartPointerForwardReference@
VProcessObject at itk@@@itk@@QBEPAVProcessObject at 1@XZ) already defined in
AuxITKLib.lib(AuxITKLib.dll)
1>ITKCommon-4.1.lib(itkDataObject.obj) : error LNK2005: "public: __thiscall
itk::SmartPointerForwardReference<class itk::ProcessObject>::~
SmartPointerForwardReference<class itk::ProcessObject>(void)" (??1?$
SmartPointerForwardReference at VProcessObject@itk@@@itk@@QAE at XZ) already
defined in AuxITKLib.lib(AuxITKLib.dll)
1>     Creating library C:/users/bin/Alma-in-server/
AuxTools/AuxITK/AuxITKLib/dll/win32-vs10-release-build/Testing/Release/TestAlgorithms.lib
and object C:/users/bin/Alma-in-server/AuxTools/AuxITK/AuxITKLib/dll/
win32-vs10-release-build/Testing/Release/TestAlgorithms.exp
1>C:\users\bin\Alma-in-server\AuxTools\AuxITK\AuxITKLib\dll\
win32-vs10-release-build\Testing\Release\TestAlgorithms.exe : fatal error
LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

If we don't link the test exes with ${ITK_LIBRARIES} , then the compiler
claims that there are undefined symbols.

We can overcome the problem by using compiler-specific flags  such as
/FORCE:MULTIPLE (Visual Studio) and --allow-multiple-definition (gcc) but
this seems to be treating the symptoms and not the disease... Any hint on
how to link properly the exes?


Thanks
--
Sergio Vera

 Alma IT Systems
 C/ Vilana, 4B, 4º 1ª
 08022 Barcelona
 T. (+34) 932 380 592
 www.alma3d.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120605/7b739625/attachment.htm>


More information about the Insight-users mailing list