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

Chris Volpe ARA/SED cvolpe at ara.com
Fri Mar 18 20:28:43 EDT 2011


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<mailto: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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110319/767bd3e0/attachment.htm>


More information about the vtkusers mailing list