[Insight-users] Making ITK dlls with Visual Studio

Luis Ibanez luis.ibanez at kitware.com
Tue May 20 14:04:26 EDT 2008



Hi Pedro,


Thanks for letting us know that the CMakeLists.txt changes
worked for you.


A common problem with DLLs is that you will have different
versions laying around in multiple directories.  Therefore,
your applications are at risk of finding an incorrect
version of the DLL library and to load it.


The way you can manage this is by adding to your DLL a function
that returns the ITK version that was used for building the DLL,
and that you could enrich with a version number for the DLL itself.

The itkVersion class could be used for this.  Please see


         Insight/Code/Common/itkVersion.h

If you add to your DLL a function that instantiates an itkVersion
object and calls its methods

    static const char *GetITKVersion();
    static int GetITKMajorVersion();
    static int GetITKMinorVersion();
    static int GetITKBuildVersion();
    static const char *GetITKSourceVersion();

then you can return a number or a string that uniquely identifies
the version in your DLL.


In your application, you could construct a similar number or string
and then you could compare both of them.   If the versions don't
match, then you should search for another DLL in the list of available
libraries.


You will find this code illustrated in the itkDynamicLoader class
in Insight/Code/Common.

and the checks of Versions is illustrated in:

        Insight/Code/Common/itkObjectFactoryBase.cxx

lines 423-430.

if ( strcmp(factory->GetITKSourceVersion(),
             Version::GetITKSourceVersion()) != 0 )
     {
     itkGenericOutputMacro(<< "Possible incompatible factory load:"
                           << "\nRunning itk version :\n"
                           << Version::GetITKSourceVersion()
                           << "\nLoaded factory version:\n"
                           << factory->GetITKSourceVersion()
                           << "\nLoading factory:\n"
                           << factory->m_LibraryPath << "\n");
     }


---


     Regards,


        Luis



-----------------------------
Pedro Madrigal Bayonas wrote:
> Ok, Luis
> it works perfect.
> Can you explain more detailed what you refers to "provide a mechanism 
> for checking versions when you load the DLL"?
>  
>  thanks for your help!
> 
>  
> 
>  > Date: Sun, 18 May 2008 09:52:26 -0400
>  > From: luis.ibanez at kitware.com
>  > To: pmb_007 at hotmail.com
>  > CC: insight-users at itk.org
>  > Subject: Re: [Insight-users] Making ITK dlls with Visual Studio
>  >
>  >
>  >
>  > Hi Pedro,
>  >
>  > The basic step is to replace
>  >
>  >
>  > ADD_EXECUTABLE(GradientImageFilter GradientImageFilter.cxx)
>  >
>  >
>  > with
>  >
>  > ADD_LIBRARY(GradientImageFilter SHARED GradientImageFilter.cxx)
>  >
>  >
>  > in your CMakeLists.txt file.
>  >
>  >
>  > However, in addition to that, you need to add an explicit instantiation
>  > for the type in the .cxx file, add the EXPORT symbol, and provide a
>  > mechanism for checking versions when you load the DLL.
>  >
>  >
>  > All of this is illustrated in the VolViewPlugins directory in
>  > InsightApplications:
>  >
>  > InsightApplications/VolViewPlugins
>  >
>  >
>  >
>  > Regards,
>  >
>  >
>  > Luis
>  >
>  >
>  >
>  > ------------------------------
>  > Pedro Madrigal Bayonas wrote:
>  > > Hi, i'm new ITK user. My question is:
>  > >
>  > > anybody knows how to obtain DLLs (not .exe) when compiling the proyect
>  > > with Visual Studio 6.0?
>  > > For example, how can i make the Filter GradientImageFilter.dll instead
>  > > GradientImageFilter.exe??
>  > > It would be fantastic if someone send me the code showing me the 
> way to
>  > > do this with this filter.
>  > >
>  > > Regards,
>  > >
>  > >
>  > > Thanks
>  > >
>  > > 
> ------------------------------------------------------------------------
>  > > Tecnología, moda, motor, viajes,.suscríbete a nuestros boletines para
>  > > estar siempre a la última MSN Newsletters
>  > > 
> <http://newsletters.msn.com/hm/maintenanceeses.asp?L=ES&C=ES&P=WCMaintenance&Brand=WL&RU=http%3a%2f%2fmail.live.com>
>  > >
>  > >
>  > > 
> ------------------------------------------------------------------------
>  > >
>  > > _______________________________________________
>  > > Insight-users mailing list
>  > > Insight-users at itk.org
>  > > http://www.itk.org/mailman/listinfo/insight-users
> 
> 
> ------------------------------------------------------------------------
> Tecnología, moda, motor, viajes,.suscríbete a nuestros boletines para 
> estar siempre a la última MSN Newsletters 
> <http://newsletters.msn.com/hm/maintenanceeses.asp?L=ES&C=ES&P=WCMaintenance&Brand=WL&RU=http%3a%2f%2fmail.live.com>
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> 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