Slicer3:Module Link Setup for Windows
When making a new library or module for Slicer3 you need to carefully set things up so for building. Best thing to do is copy an existing directory that does something similar to what you have in mind and then change things to match your module setup.
Definitions
LibraryName is the first argument to ADD_LIBRARY in CMakeLists for your directory.
LIRBARYNAME is the argument to PROJECT() at the top of the CMakeLists
Files to Change/Create
vtkLibraryNameConfigure.h.in -- just copy and rename an example one.
vtkLibraryName.h -- copy and rename example one and have it include vtkLibraryNameWin32Header.h (note that this .h file will be in your build directory and is made from the .h.in file above).
vtkLibraryNameWin32Header.h -- make the following changes:
#ifndef __vtkLibraryNameWin32Header_h #define __vtkLibraryNameWin32Header_h #include <vtkLibraryNameConfigure.h> #if defined(WIN32) && !defined(VTKSLICER_STATIC) #if defined(LibraryName_EXPORTS) #define VTK_LIBRARYNAME_EXPORT __declspec( dllexport ) #else #define VTK_LIBRARYNAME_EXPORT __declspec( dllimport ) #endif #else #define VTK_LIBRARYNAME_EXPORT #endif #endif
In your code
In the .h files for your classes:
#include "vtkLibraryName.h"
Declare your classes as:
class VTK_LIBRARYNAME_EXPORT vtkMyClass : public vtkMySuperClass
CMakeLists.txt should contain:
CONFIGURE_FILE( ${LIBRARYNAME_SOURCE_DIR}/vtkLibraryNameConfigure.h.in ${LIBRARYNAME_BINARY_DIR}/vtkLibraryNameConfigure.h )
I still get linker errors
If you still get the linker errors lnk2001 or lnk 2019 make sure that you declared the copy constructor and the assignment operator:
vtkMyClass(const vtkMyClass&); void operator=(const vtkMyClass&);