[Insight-users] Problem for building DLL from ITK

Luis Ibanez luis.ibanez at kitware.com
Mon May 12 12:54:49 EDT 2008



Hi Bo,


Thaks for posting the additional information.

The problem seems to be that you are using an
inconsistent naming for symbols.



Currently you have:

ADD_LIBRARY(ITKLib SHARED ITKLib32.cpp StdAfx.cpp)
            ^^^^^^

and

#ifdef ITKLIB32_EXPORTS
       ^^^^^^^^

#define ITKLIB32_API __declspec(dllexport)
#else
#define ITKLIB32_API __declspec(dllimport)
#endif



The symbol "ITKLIB32_EXPORTS" doesn't match the name of
the library. The symbol should be "libraryname_EXPORTS"


More specifically, in your case it should be

         #ifdef ITKLib_EXPORTS



   Regards,


      Luis



--------------
Bo Zhou wrote:
> Hi Luis,
>    Those are wizard-generated files and they do include the Maco for Dll purpose. 
>    If I don't use Cmake, everything is OK. However, I want to use C++ classes from ITK, and I don't want to assign the locations of ITK source files manually. 
>    The files below don't include any ITK classes, I just want to make sure the Cmake can generate dll smoothly.
>    And again, thank you so much for your help:)
> 
> ITKLib32.h   
> ---------------------------------------------
> #ifdef ITKLIB32_EXPORTS
> #define ITKLIB32_API __declspec(dllexport)
> #else
> #define ITKLIB32_API __declspec(dllimport)
> #endif
> 
> // This class is exported from the ITKLib32.dll
> class ITKLIB32_API CITKLib32 {
> public:
> 	CITKLib32(void);
> 	// TODO: add your methods here.
> };
> 
> extern ITKLIB32_API int nITKLib32;
> 
> ITKLIB32_API int fnITKLib32(void);
> ----------------------------------------------
> 
> 
> ITKLib32.cpp 
> --------------------------------------------------
> #include "stdafx.h"
> #include "ITKLib32.h"
> 
> BOOL APIENTRY DllMain( HANDLE hModule, 
>                        DWORD  ul_reason_for_call, 
>                        LPVOID lpReserved
> 					 )
> {
>     switch (ul_reason_for_call)
> 	{
> 		case DLL_PROCESS_ATTACH:
> 		case DLL_THREAD_ATTACH:
> 		case DLL_THREAD_DETACH:
> 		case DLL_PROCESS_DETACH:
> 			break;
>     }
>     return TRUE;
> }
> 
> 
> // This is an example of an exported variable
> ITKLIB32_API int nITKLib32=0;
> 
> // This is an example of an exported function.
> ITKLIB32_API int fnITKLib32(void)
> {
> 	return 42;
> }
> 
> // This is the constructor of a class that has been exported.
> // see ITKLib32.h for the class definition
> CITKLib32::CITKLib32()
> { 
> 	return; 
> }
> --------------------------------------------------------------
> 
> 
> 
> ------------------				 
> Bo Zhou
> 
> -------------------------------------------------------------
> From:Luis Ibanez
> Date:2008-04-21 18:36:55
> To:Bo Zhou
> FW:insight-users
> Subject:Re: [Insight-users] Problem for building DLL from ITK
> 
> 
> Hi Bo,
> 
> Could you please post to the mailing list the source code
> of the ITKLib32.cpp file ?
> 
> It is likely that you are missig some export symbols of the type:
> 
>     __declspec(dllexport)
>     __declspec(dllimport)
> 
> 
> Thanks
> 
> 
>      Luis
> 
> 
> ------------------
> Bo Zhou wrote:
> 
>>Hi All,
>>  I've been trying to build a DLL from ITK using MSDEV 6.0. However I encountered some problems and hope someone can help me and I really appreciate.
>>
>>  To be simple enough, my test followed these steps:
>>
>>1. I used wizard-generated source files from MSDEV and put them together with the following Cmakelist.txt file.
>>    ---------------------------------------------------------------  
>>    PROJECT(ITKLib)
>>
>>    # Find ITK.
>>    FIND_PACKAGE(ITK)
>>    IF(ITK_FOUND)
>>     INCLUDE(${ITK_USE_FILE})
>>    ELSE(ITK_FOUND)
>>     MESSAGE(FATAL_ERROR
>>          "Cannot build without ITK.  Please set ITK_DIR.")
>>    ENDIF(ITK_FOUND)
>>
>>    ADD_LIBRARY(ITKLib SHARED ITKLib32.cpp StdAfx.cpp) 
>>    --------------------------------------------------------------
>>2. Cmake 2.4 was used to configure the project and the project was built into another directory.(Cmake did find the ITK directory)
>>3. I opened the generated project and built all. Following messages appeared:
>>    D:\Image_Registration\Program\ITKLib\ITKLib32.cpp(25) : error C2491: 'nITKLib32' : definition of dllimport data not allowed
>>    D:\Image_Registration\Program\ITKLib\ITKLib32.cpp(29) : error C2491: 'fnITKLib32' : definition of dllimport function not allowed
>>    D:\Image_Registration\Program\ITKLib\ITKLib32.cpp(36) : warning C4273: 'CITKLib32::CITKLib32' : inconsistent dll linkage.  dllexport assumed.
>>
>>
>>    The source files shall be ok because they are generated by wizard and I did generated DLL successfully without using Cmake.
>>    Has anyone had the similar problem before? your guidline will be really helpful and I really appreciate it.
>> 
>>   Thanks and have a nice day!
>>
>> 
>>
>>   
>> 				
>>--------------
>>Bo Zhou
>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users at itk.org
>>http://www.itk.org/mailman/listinfo/insight-users
>>
> 
> .


More information about the Insight-users mailing list