[vtkusers] Using VTK with CMake: link errors
David Doria
daviddoria+vtk at gmail.com
Tue Aug 10 16:43:57 EDT 2010
On Tue, Aug 10, 2010 at 3:40 PM, Nicholas Kinar <n.kinar at usask.ca> wrote:
> Hello,
>
> I'm writing a program for a research application, and I would like to use
> Cmake as the makefile generation tool. Here is the basic information
> pertaining to my development platform:
>
> cmake version 2.8.2
> i686-apple-darwin10-gcc-4.2.1
> Snow Leopard 10.6.4 on an x86_64 Macbook Pro
> vtk-5.6.0 (stable version)
>
> The VTK libraries have been installed into the /usr/local directory.
>
> I've written a CMakeLists.txt file to generate the makefile. Here is the
> file:
>
> cmake_minimum_required (VERSION 2.6)
> project (fdtd-cuda-1)
> find_package(VTK REQUIRED)
> include_directories( ${VTK_INCLUDE_DIRS} )
> include_directories(/Volumes/FILES/CODE-LIBRARY/utilities)
> include_directories(/Volumes/FILES/Programs/common/TNT)
> include_directories(/Volumes/FILES/Programs/common/boost/boost_1_43_0)
> include (${VTK_USE_FILE})
> add_executable (fdtd-cuda-1 main.cpp)
> target_link_libraries(fdtd-cuda-1 ${VTK_LIBS})
>
> Within the main.cpp file, of my C++ program I am using the following VTK
> headers:
>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkInteractorStyleImage.h>
> #include <vtkRenderer.h>
> #include <vtkJPEGReader.h>
> #include <vtkImageActor.h>
> #include <vtkCommand.h>
> #include <vtkCallbackCommand.h>
> #include <vtkSmartPointer.h>
>
> Although CMake generates the UNIX makefile properly, it appears that the
> linker cannot find some symbols:
>
> Linking CXX executable fdtd-cuda-1
> Undefined symbols:
> "vtkRenderer::New()", referenced from:
> vtkSmartPointer<vtkRenderer>::New() in main.cpp.o
> "vtkRenderWindowInteractor::SetRenderWindow(vtkRenderWindow*)", referenced
> from:
> test_VTK() in main.cpp.o
> "vtkRenderer::ResetCamera()", referenced from:
> test_VTK() in main.cpp.o
> "vtkJPEGReader::New()", referenced from:
> vtkSmartPointer<vtkJPEGReader>::New() in main.cpp.o
> "vtkSmartPointerBase::vtkSmartPointerBase(vtkObjectBase*,
> vtkSmartPointerBase::NoReference const&)", referenced from:
> vtkSmartPointer<vtkJPEGReader>::vtkSmartPointer(vtkJPEGReader*,
> vtkSmartPointerBase::NoReference const&)in main.cpp.o
> vtkSmartPointer<vtkImageActor>::vtkSmartPointer(vtkImageActor*,
> vtkSmartPointerBase::NoReference const&)in main.cpp.o
> vtkSmartPointer<vtkRenderer>::vtkSmartPointer(vtkRenderer*,
> vtkSmartPointerBase::NoReference const&)in main.cpp.o
> vtkSmartPointer<vtkRenderWindow>::vtkSmartPointer(vtkRenderWindow*,
> vtkSmartPointerBase::NoReference const&)in main.cpp.o
>
> vtkSmartPointer<vtkRenderWindowInteractor>::vtkSmartPointer(vtkRenderWindowInteractor*,
> vtkSmartPointerBase::NoReference const&)in main.cpp.o
>
> vtkSmartPointer<vtkInteractorStyleImage>::vtkSmartPointer(vtkInteractorStyleImage*,
> vtkSmartPointerBase::NoReference const&)in main.cpp.o
> "vtkInteractorStyleImage::New()", referenced from:
> vtkSmartPointer<vtkInteractorStyleImage>::New() in main.cpp.o
> "vtkImageAlgorithm::GetOutput()", referenced from:
> test_VTK() in main.cpp.o
> "vtkRenderWindowInteractor::New()", referenced from:
> vtkSmartPointer<vtkRenderWindowInteractor>::New() in main.cpp.o
> "vtkImageActor::New()", referenced from:
> vtkSmartPointer<vtkImageActor>::New() in main.cpp.o
> "vtkRenderWindow::New()", referenced from:
> vtkSmartPointer<vtkRenderWindow>::New() in main.cpp.o
> "vtkSmartPointerBase::~vtkSmartPointerBase()", referenced from:
> vtkSmartPointer<vtkInteractorStyleImage>::~vtkSmartPointer()in
> main.cpp.o
> vtkSmartPointer<vtkRenderWindowInteractor>::~vtkSmartPointer()in
> main.cpp.o
> vtkSmartPointer<vtkRenderWindow>::~vtkSmartPointer()in main.cpp.o
> vtkSmartPointer<vtkRenderer>::~vtkSmartPointer()in main.cpp.o
> vtkSmartPointer<vtkImageActor>::~vtkSmartPointer()in main.cpp.o
> vtkSmartPointer<vtkJPEGReader>::~vtkSmartPointer()in main.cpp.o
> "vtkRenderer::AddActor(vtkProp*)", referenced from:
> test_VTK() in main.cpp.o
> ld: symbol(s) not found
> collect2: ld returned 1 exit status
> make[2]: *** [fdtd-cuda-1] Error 1
> make[1]: *** [CMakeFiles/fdtd-cuda-1.dir/all] Error 2
> make: *** [all] Error 2
>
> What is happening here, and what should I change in my CmakeLists.txt file
> to be able to properly compile this program? It appears that there is a
> problem with the linker being unable to find some libraries.
>
> Nicholas
Try this
target_link_libraries(fdtd-cuda-1 vtkHybrid)
(that is, replace ${VTK_LIBS} with vtkHybrid)
If that works you'll have to ask the CMake folks why what you did didn't work.
Thanks,
David
More information about the vtkusers
mailing list