[Insight-users] ITK and managed C++ .NET

Nick Arini nick.arini at amersham.com
Fri Jul 9 06:53:05 EDT 2004


John,

I am still having trouble getting ITK to work with managed C++. I have 
tried approaching the problem from 2 directions.

1, Create a managed C++ project (Windows forms app or .NET class library). 
Include some itk headers and a bit of itk code in the form or in a managed 
class. Copy the Additional Include Directories, Additional Library 
Directories and Additional Dependencies lines from a CMake generated 
unmanaged project (which compiles just fine) to the current project 
properties. Upon compilation I get the errors below.

2, Create an unmanaged project using CMake with ITK set up. Set Use 
Managed Extensions to Yes in the project properties. Add a new item to the 
project like a .NET form. I get a message box with the error:

Managed components can only be added to managed projects. Please convert 
the project to managed. 


I am obviously missing something. Can you tell me how you set up a project 
so these things work together?

Thanks,

Nick


<begin managed code>

// ITKWrapper.h

#pragma once

#include "itkImage.h"
#include "itkImageFileReader.h"

using namespace System;

namespace ITKWrapper
{

        public __gc class ConvertITKWrapper
        {
                public:
                        void doConversion(char *fname1, char *fname2)
                        {
                                // Read in the image 
                                typedef  unsigned int PixelType;
                                typedef itk::Image< PixelType,  2 >   ImageType;
                                typedef itk::ImageFileReader< ImageType >  ReaderType;

                                ReaderType::Pointer reader = 
ReaderType::New();
                                reader->SetFileName( fname1 );

                                reader->Update();
                        }
        };
}

<end managed code>

<begin compile errors>

Compiling...
ITKWrapper.cpp
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(134) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(135) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(136) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(137) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(138) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(139) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(140) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(141) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(142) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(143) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(144) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(145) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(146) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(147) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkEventObject.h(149) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::EventObject' with 
/GR-; unpredictable behavior may result
c:\Program Files\ITK\Insight\Code\Common\itkObjectFactory.h(53) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::LightObject' with 
/GR-; unpredictable behavior may result
        c:\Program Files\ITK\Insight\Code\Common\itkObjectFactory.h(51) : 
while compiling class-template member function 'itk::MutexLock::Pointer 
itk::ObjectFactory<T>::Create(void)'
        with
        [
            T=itk::MutexLock::Self
        ]
        c:\Program Files\ITK\Insight\Code\Common\itkMutexLock.h(126) : see 
reference to class template instantiation 'itk::ObjectFactory<T>' being 
compiled
        with
        [
            T=itk::MutexLock::Self
        ]
c:\Program Files\ITK\Insight\Code\Common\itkObjectFactory.h(53) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::LightObject' with 
/GR-; unpredictable behavior may result
        c:\Program Files\ITK\Insight\Code\Common\itkObjectFactory.h(51) : 
while compiling class-template member function 
'itk::MultiThreader::Pointer itk::ObjectFactory<T>::Create(void)'
        with
        [
            T=itk::MultiThreader::Self
        ]
        c:\Program Files\ITK\Insight\Code\Common\itkMultiThreader.h(134) : 
see reference to class template instantiation 'itk::ObjectFactory<T>' 
being compiled
        with
        [
            T=itk::MultiThreader::Self
        ]
c:\Program Files\ITK\Insight\Code\Common\itkObjectFactory.h(53) : warning 
C4541: 'dynamic_cast' used on polymorphic type 'itk::LightObject' with 
/GR-; unpredictable behavior may result
        c:\Program Files\ITK\Insight\Code\Common\itkObjectFactory.h(51) : 
while compiling class-template member function 
'itk::FastMutexLock::Pointer itk::ObjectFactory<T>::Create(void)'
        with
        [
            T=itk::FastMutexLock::Self
        ]
        c:\Program Files\ITK\Insight\Code\Common\itkFastMutexLock.h(61) : 
see reference to class template instantiation 'itk::ObjectFactory<T>' 
being compiled
        with
        [
            T=itk::FastMutexLock::Self
        ]
Linking...
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: void __thiscall 
std::_Mutex::_Unlock(void)" (?_Unlock at _Mutex@std@@QAEXXZ) already defined 
in libcpmt.lib(xmutex.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: void __thiscall 
std::_Mutex::_Lock(void)" (?_Lock at _Mutex@std@@QAEXXZ) already defined in 
libcpmt.lib(xmutex.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: void __thiscall 
std::locale::facet::_Register(void)" (?_Register at facet@locale at std@@QAEXXZ) 
already defined in libcpmt.lib(locale0.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: void __thiscall 
std::locale::facet::_Incref(void)" (?_Incref at facet@locale at std@@QAEXXZ) 
already defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: static unsigned int 
__cdecl std::ctype<char>::_Getcat(class std::locale::facet const * *)" 
(?_Getcat@?$ctype at D@std@@SAIPAPBVfacet at locale@2@@Z) already defined in 
ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: class 
std::locale::facet const * __thiscall std::locale::_Getfacet(unsigned 
int)const " (?_Getfacet at locale@std@@QBEPBVfacet at 12@I at Z) already defined in 
libcpmt.lib(locale0.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: __thiscall 
std::_Lockit::~_Lockit(void)" (??1_Lockit at std@@QAE at XZ) already defined in 
libcpmt.lib(xlock.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: __thiscall 
std::_Lockit::_Lockit(int)" (??0_Lockit at std@@QAE at H@Z) already defined in 
libcpmt.lib(xlock.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: __thiscall 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> >::~basic_string<char,struct 
std::char_traits<char>,class std::allocator<char> >(void)" 
(??1?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QAE at XZ) 
already defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: class 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> > & __thiscall std::basic_string<char,struct 
std::char_traits<char>,class std::allocator<char> >::operator+=(class 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> > const &)" 
(??Y?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QAEAAV01 at ABV01@@Z) 
already defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: __thiscall 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> >::basic_string<char,struct 
std::char_traits<char>,class std::allocator<char> >(class 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> > const &)" 
(??0?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QAE at ABV01@@Z) 
already defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: __thiscall 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> >::basic_string<char,struct 
std::char_traits<char>,class std::allocator<char> >(char const *)" 
(??0?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QAE at PBD@Z) 
already defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: class 
std::basic_ostream<char,struct std::char_traits<char> > & __thiscall 
std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" 
(?flush@?$basic_ostream at DU?$char_traits at D@std@@@std@@QAEAAV12 at XZ) already 
defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: void __thiscall 
std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" 
(?_Osfx@?$basic_ostream at DU?$char_traits at D@std@@@std@@QAEXXZ) already 
defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: void __thiscall 
std::ios_base::clear(int,bool)" (?clear at ios_base@std@@QAEXH_N at Z) already 
defined in libcpmt.lib(ios.obj)
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: class 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> > & __thiscall std::basic_string<char,struct 
std::char_traits<char>,class std::allocator<char> >::append(unsigned 
int,char)" 
(?append@?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QAEAAV12 at ID@Z) 
already defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: unsigned int __thiscall 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> >::max_size(void)const " 
(?max_size@?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QBEIXZ) 
already defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: class 
std::basic_string<char,struct std::char_traits<char>,class 
std::allocator<char> > & __thiscall std::basic_string<char,struct 
std::char_traits<char>,class std::allocator<char> >::erase(unsigned 
int,unsigned int)" 
(?erase@?$basic_string at DU?$char_traits at D@std@@V?$allocator at D@2@@std@@QAEAAV12 at II@Z) 
already defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: __thiscall 
std::locale::~locale(void)" (??1locale at std@@QAE at XZ) already defined in 
ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: class std::locale 
__thiscall std::ios_base::getloc(void)const " 
(?getloc at ios_base@std@@QBE?AVlocale at 2@XZ) already defined in 
ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: int __thiscall 
std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" 
(?sputc@?$basic_streambuf at DU?$char_traits at D@std@@@std@@QAEHD at Z) already 
defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: class 
std::basic_ostream<char,struct std::char_traits<char> > & __thiscall 
std::basic_ostream<char,struct std::char_traits<char> 
>::operator<<(unsigned int)" 
(??6?$basic_ostream at DU?$char_traits at D@std@@@std@@QAEAAV01 at I@Z) already 
defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "class 
std::basic_ostream<char,struct std::char_traits<char> > & __cdecl 
std::operator<<<struct std::char_traits<char> >(class 
std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" 
(??$?6U?$char_traits at D@std@@@std@@YAAAV?$basic_ostream at DU?$char_traits at D@std@@@0 at AAV10@PBD at Z) 
already defined in ITKWrapper.obj
msvcprt.lib(MSVCP71.dll) : error LNK2005: "public: char __thiscall 
std::basic_ios<char,struct std::char_traits<char> >::widen(char)const " 
(?widen@?$basic_ios at DU?$char_traits at D@std@@@std@@QBEDD at Z) already defined 
in ITKWrapper.obj
C:\Documents and 
Settings\Nick.Arini\Desktop\sandbox\ITKWrapper\Release\ITKWrapper.dll : 
fatal error LNK1169: one or more multiply defined symbols found

Build log was saved at "file://c:\Documents and 
Settings\Nick.Arini\Desktop\sandbox\ITKWrapper\ITKWrapper\Release\BuildLog.htm"
ITKWrapper - 25 error(s), 18 warning(s)


---------------------- Done ----------------------

    Build: 0 succeeded, 1 failed, 0 skipped

<end compile errors>






"John Biddiscombe" <jbiddiscombe at skippingmouse.co.uk>
07/07/2004 11:41

 
        To:     "Nick Arini" <nick.arini at amersham.com>
        cc:     <Insight-users at itk.org>
        Subject:        Re: [Insight-users] ITK and managed C++ .NET


> Is wrapping necessary for use with C#?

Well, strictly speaking yes. But why bother with C# when you can do
everything from (managed) C++?
I have a main window which uses C++ forms and vtk renderwindows embedded,
internally I've got a mixture of vtk and itk pipelines, but also on my 
forms
I've got components and controls I've downloaded which are written in C#.
You can call C# components directly from managed C++, so do all your work 
in
C++, create assemblies with C++, you can then call these directly from C#.
Ok you can't call the itk pieplines directly from C#, but you can create
your own dll's (assemblies) that encapsulate all your processing using
vtk/itk, then once they're callable from an assembly, you can reference it
from a C# module.

Personally, I'd use C++ and call C# when you need it rather than the other
way around, but that's only my $0.02.

Any jobs going for .Net C+++ vtk/itk people out there :) ?

JB






More information about the Insight-users mailing list