[vtkusers] Building a VTK-leveraging DLL and driver EXE using CMake -- Need help!

David Partyka david.partyka at kitware.com
Fri Mar 18 20:46:33 EDT 2011


Your dll has no lib because you are not exporting any symbols. You'll want
to make a common header for your classes that has a block similar to

http://stackoverflow.com/questions/4276549/exporting-symbols-when-compiling-dll-msvc

<http://stackoverflow.com/questions/4276549/exporting-symbols-when-compiling-dll-msvc>And
then in each of your class declarations use your libraries export macro.

For example classes in vtkCommon are exported like so:

class VTK_COMMON_EXPORT vtkArray : public vtkObject

And VTK_COMMON_EXPORT is defined by this block in vtkWin32Header.h

 #if defined(vtkCommon_EXPORTS)
  #define VTK_COMMON_EXPORT VTK_ABI_EXPORT
 #else
  #define VTK_COMMON_EXPORT VTK_ABI_IMPORT
 #endif


And VTK_ABI_IMPORT/VTK_ABI_EXPORT are defined in vtkABI.h

#if defined(_WIN32)
# define VTK_ABI_IMPORT __declspec(dllimport)
# define VTK_ABI_EXPORT __declspec(dllexport)
# define VTK_ABI_HIDDEN
#elif __GNUC__ >= 4
# define VTK_ABI_IMPORT __attribute__ ((visibility("default")))
# define VTK_ABI_EXPORT __attribute__ ((visibility("default")))
# define VTK_ABI_HIDDEN __attribute__ ((visibility("hidden")))
#else
# define VTK_ABI_IMPORT
# define VTK_ABI_EXPORT
# define VTK_ABI_HIDDEN
#endif

On Fri, Mar 18, 2011 at 8:28 PM, Chris Volpe ARA/SED <cvolpe at ara.com> wrote:

> Hello-
>
>
>
> I am trying to set up a source tree which will allow CMake to create a
> MSVC++ .sln file that contains the following two projects:
>
> 1.       A DLL (called “FeatureViewer”) containing a vanilla C++ class
> that links against several VTK kits (Graphics, Rendering, and Hybrid).
>
> 2.       An EXE (called “TestDriver”) that links against the
> aforementioned library containing the vanilla C++ class.
>
>
>
> I have built VTK 5.6 from source, and I want to deliver the DLL, LIB, and
> class header file from (1) above to a co-worker who has his own application
> and wants to use the functionality I’m encapsulating, but he doesn’t want to
> “vtk-ify” his build process. The EXE in (2) above is simply my test driver
> for (1).
>
>
>
> My problem is that the EXE won’t build because the generated project is
> spuriously looking for vtk libraries (e.g. vtkGraphics.lib et. al.) at link
> time that it doesn’t directly reference, and it doesn’t know where to find
> them. The EXE shouldn’t need to know about them because their use is
> strictly within the FeatureViewer library. If I go into the EXE project
> properties and manually delete the references to vtkGraphics.lib et. al.
> from the linker->input->additional-dependencies list, I get a whole bunch of
> unresolved symbols for the stuff in the vtk libs. I figured out that part of
> my problem is that the FeatureViewer library was being built static (there
> was no dll), so I changed the CMakeLists.txt file for the library so that it
> builds SHARED. Now, I get a DLL, but there’s now no .lib for my EXE to link
> against.
>
>
>
> Can someone tell me what I’m doing wrong? Here’s what I’m doing in the
> three CMakeLists.txt files (top level, library subdir, executable subdir)
>
>
>
> Top Level CMakeLists.txt:
>
> CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
>
> IF(COMMAND CMAKE_POLICY)
>
>   CMAKE_POLICY(SET CMP0003 NEW)
>
> ENDIF(COMMAND CMAKE_POLICY)
>
> PROJECT(FeatureViewer)
>
> SUBDIRS (
>
>   FeatureViewer
>
>   TestDriver
>
> )
>
> #INCLUDE_DIRECTORIES(${FeatureViewer_SOURCE_DIR}/FeatureViewer)
>
>
>
> Library CMakeLists.txt file in FeatureViewer subdir:
>
>
>
> SET (FeatureViewer_SRCS
>
>   FeatureViewer.cxx
>
> )
>
> IF(NOT VTK_BINARY_DIR)
>
> FIND_PACKAGE(VTK REQUIRED)
>
> IF(NOT VTK_USE_RENDERING)
>
>   MESSAGE(FATAL_ERROR "Example ${PROJECT_NAME} requires
> VTK_USE_RENDERING.")
>
> ENDIF(NOT VTK_USE_RENDERING)
>
> INCLUDE(${VTK_USE_FILE})
>
> ENDIF(NOT VTK_BINARY_DIR)
>
> ADD_LIBRARY(FeatureViewer SHARED ${FeatureViewer_SRCS})
>
> TARGET_LINK_LIBRARIES(FeatureViewer vtkGraphics vtkRendering vtkHybrid)
>
>
>
> Executable CMakeLists.txt file in TestDriver subdir:
>
>
>
> ADD_EXECUTABLE(TestDriver TestDriver.cxx)
>
> TARGET_LINK_LIBRARIES(TestDriver FeatureViewer)
>
> INCLUDE_DIRECTORIES(${FeatureViewer_SOURCE_DIR}/FeatureViewer)
>
>
>
> When I try to build, FeatureViewer builds ok (DLL is there, but no LIB in
> sight), but TestDriver fails with the following:
>
> 2>LINK : fatal error LNK1104: cannot open file
> '..\FeatureViewer\Debug\FeatureViewer.lib'
>
>
>
> This seems straightforward enough. Can anyone tell me what I’m doing wrong?
> Please let me know if the cmake mailing list is the more appropriate venue
> for this question, and I will re-post there. Thanks so much in advance for
> any assistance you can provide.
>
>
>
> Chris
>
> --
> Christopher R. Volpe,
> Ph.D.                                                           Email:
> cvolpe at ara.com
>
> Senior Scientist, Information Exploitation Systems             Main Desk:
> 919-582-3300
>
> Applied Research Associates, Inc <http://www.ara.com/>
> Direct: 919-582-3380
>
> 8537 Six Forks Rd., Suite
> 6000                                                            Fax :
> 919-582-3301
>
> Raleigh, NC 27615                                         Web:
> http://www.ara.com/offices/NC.htm
>
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110318/9c45de8b/attachment.htm>


More information about the vtkusers mailing list