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<div><br></div><div><a href="http://stackoverflow.com/questions/4276549/exporting-symbols-when-compiling-dll-msvc">http://stackoverflow.com/questions/4276549/exporting-symbols-when-compiling-dll-msvc</a></div>
<div><br></div><div><a href="http://stackoverflow.com/questions/4276549/exporting-symbols-when-compiling-dll-msvc"></a>And then in each of your class declarations use your libraries export macro. </div><div><br></div><div>
For example classes in vtkCommon are exported like so:</div><div><br></div><div>class VTK_COMMON_EXPORT vtkArray : public vtkObject</div><div><br></div><div>And VTK_COMMON_EXPORT is defined by this block in vtkWin32Header.h</div>
<div><br></div><div><div> #if defined(vtkCommon_EXPORTS)</div><div> #define VTK_COMMON_EXPORT VTK_ABI_EXPORT</div><div> #else</div><div> #define VTK_COMMON_EXPORT VTK_ABI_IMPORT</div><div> #endif</div><div><br></div><div>
<br></div>And VTK_ABI_IMPORT/VTK_ABI_EXPORT are defined in vtkABI.h</div><div><br></div><div><div>#if defined(_WIN32)</div><div># define VTK_ABI_IMPORT __declspec(dllimport)</div><div># define VTK_ABI_EXPORT __declspec(dllexport)</div>
<div># define VTK_ABI_HIDDEN</div><div>#elif __GNUC__ >= 4</div><div># define VTK_ABI_IMPORT __attribute__ ((visibility("default")))</div><div># define VTK_ABI_EXPORT __attribute__ ((visibility("default")))</div>
<div># define VTK_ABI_HIDDEN __attribute__ ((visibility("hidden")))</div><div>#else</div><div># define VTK_ABI_IMPORT</div><div># define VTK_ABI_EXPORT</div><div># define VTK_ABI_HIDDEN</div><div>#endif</div><div>
<br></div><div class="gmail_quote">On Fri, Mar 18, 2011 at 8:28 PM, Chris Volpe ARA/SED <span dir="ltr"><<a href="mailto:cvolpe@ara.com">cvolpe@ara.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal">Hello-</p><p class="MsoNormal"> </p><p class="MsoNormal">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:</p>
<p><span>1.<span style="font:7.0pt "Times New Roman""> </span></span>A DLL (called “FeatureViewer”) containing a vanilla C++ class that links against several VTK kits (Graphics, Rendering, and Hybrid). </p>
<p><span>2.<span style="font:7.0pt "Times New Roman""> </span></span>An EXE (called “TestDriver”) that links against the aforementioned library containing the vanilla C++ class. </p><p class="MsoNormal"> </p>
<p class="MsoNormal">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).</p>
<p class="MsoNormal"> </p><p class="MsoNormal">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. </p>
<p class="MsoNormal"> </p><p class="MsoNormal">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)</p><p class="MsoNormal"> </p>
<p class="MsoNormal">Top Level CMakeLists.txt: </p><p class="MsoNormal" style="margin-left:.5in">CMAKE_MINIMUM_REQUIRED(VERSION 2.4)</p><p class="MsoNormal" style="margin-left:.5in">IF(COMMAND CMAKE_POLICY)</p><p class="MsoNormal" style="margin-left:.5in">
CMAKE_POLICY(SET CMP0003 NEW)</p><p class="MsoNormal" style="margin-left:.5in">ENDIF(COMMAND CMAKE_POLICY)</p><p class="MsoNormal" style="margin-left:.5in">PROJECT(FeatureViewer)</p><p class="MsoNormal" style="margin-left:.5in">
SUBDIRS (</p><p class="MsoNormal" style="margin-left:.5in"> FeatureViewer</p><p class="MsoNormal" style="margin-left:.5in"> TestDriver</p><p class="MsoNormal" style="margin-left:.5in">)</p><p class="MsoNormal" style="margin-left:.5in">
#INCLUDE_DIRECTORIES(${FeatureViewer_SOURCE_DIR}/FeatureViewer)</p><p class="MsoNormal"> </p><p class="MsoNormal">Library CMakeLists.txt file in FeatureViewer subdir:</p><p class="MsoNormal"> </p><p class="MsoNormal" style="margin-left:.5in">
SET (FeatureViewer_SRCS</p><p class="MsoNormal" style="margin-left:.5in"> FeatureViewer.cxx</p><p class="MsoNormal" style="margin-left:.5in">)</p><p class="MsoNormal" style="margin-left:.5in">IF(NOT VTK_BINARY_DIR)</p><p class="MsoNormal" style="margin-left:.5in">
FIND_PACKAGE(VTK REQUIRED)</p><p class="MsoNormal" style="margin-left:.5in">IF(NOT VTK_USE_RENDERING)</p><p class="MsoNormal" style="margin-left:.5in"> MESSAGE(FATAL_ERROR "Example ${PROJECT_NAME} requires VTK_USE_RENDERING.")</p>
<p class="MsoNormal" style="margin-left:.5in">ENDIF(NOT VTK_USE_RENDERING)</p><p class="MsoNormal" style="margin-left:.5in">INCLUDE(${VTK_USE_FILE})</p><p class="MsoNormal" style="margin-left:.5in">ENDIF(NOT VTK_BINARY_DIR)</p>
<p class="MsoNormal" style="margin-left:.5in">ADD_LIBRARY(FeatureViewer SHARED ${FeatureViewer_SRCS})</p><p class="MsoNormal" style="margin-left:.5in">TARGET_LINK_LIBRARIES(FeatureViewer vtkGraphics vtkRendering vtkHybrid)</p>
<p class="MsoNormal"> </p><p class="MsoNormal">Executable CMakeLists.txt file in TestDriver subdir:</p><p class="MsoNormal"> </p><p class="MsoNormal" style="margin-left:.5in">ADD_EXECUTABLE(TestDriver TestDriver.cxx)</p>
<p class="MsoNormal" style="margin-left:.5in">
TARGET_LINK_LIBRARIES(TestDriver FeatureViewer)</p><p class="MsoNormal" style="margin-left:.5in">INCLUDE_DIRECTORIES(${FeatureViewer_SOURCE_DIR}/FeatureViewer)</p><p class="MsoNormal"> </p><p class="MsoNormal">When I try to build, FeatureViewer builds ok (DLL is there, but no LIB in sight), but TestDriver fails with the following:</p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:"Courier New"">2>LINK : fatal error LNK1104: cannot open file '..\FeatureViewer\Debug\FeatureViewer.lib'</span></p><p class="MsoNormal"> </p>
<p class="MsoNormal">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.</p>
<p class="MsoNormal"> </p><p class="MsoNormal"><span style="font-size:24.0pt;font-family:"Monotype Corsiva"">Chris</span><span style="font-size:12.0pt;font-family:"Times New Roman","serif""></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Times New Roman","serif"">--<br>Christopher R. Volpe, Ph.D. </span><span lang="FR" style="font-size:10.0pt;font-family:"Times New Roman","serif"">Email: <a href="mailto:cvolpe@ara.com" target="_blank">cvolpe@ara.com</a> </span></p>
<p class="MsoNormal"><span lang="FR" style="font-size:10.0pt;font-family:"Times New Roman","serif"">Senior Scientist, Information Exploitation Systems Main Desk: 919-582-3300</span></p><p class="MsoNormal">
<span style="font-size:10.0pt;font-family:"Times New Roman","serif""><a href="http://www.ara.com/" target="_blank">Applied Research Associates, Inc</a> Direct: 919-582-3380</span></p>
<p class="MsoNormal"><span lang="FR" style="font-size:10.0pt;font-family:"Times New Roman","serif"">8537 Six Forks Rd., Suite 6000 Fax : 919-582-3301</span></p>
<p class="MsoNormal"><span lang="FR" style="font-size:10.0pt;font-family:"Times New Roman","serif"">Raleigh, NC 27615 Web: </span><span style="font-size:10.0pt;font-family:"Times New Roman","serif""><a href="http://www.ara.com/offices/NC.htm" title="http://www.ara.com/offices/NC.htm" target="_blank">http://www.ara.com/offices/NC.htm</a></span><span lang="FR" style="font-size:10.0pt;font-family:"Times New Roman","serif""></span></p>
<p class="MsoNormal"> <span style="font-size:12.0pt"></span></p><p class="MsoNormal"> </p></div></div><br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><br></div>