[vtkusers] Using VTK with CMake: link errors

Nicholas Kinar n.kinar at usask.ca
Wed Aug 11 00:53:58 EDT 2010


Hello,

I had originally posted this question to the vtkusers mailing list.  
However, after receiving feedback from other VTK users it is also 
apparent that there is a possibility my question belongs on the cmake 
mailing list.

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 (binary version from website)
i686-apple-darwin10-gcc-4.2.1
llvm version 2.6svn,  Apple Build #2207-05
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 tried the most recent release version of CMake pulled from git and 
the binary (pre-packaged) version on the Kitware website.  Both generate 
makefiles with the same error on Mac OS X.

I've written a CMakeLists.txt file to generate the makefile.  This 
CMakeLists.txt file works well on GNU/Linux (Ubuntu x86_64, 
2.6.32-24-generic kernel) with gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3 and GNU 
ld (GNU Binutils for Ubuntu) 2.20.1-system.20100303.  On GNU/Linux, the 
CMakeLists.txt file generates a makefile that successfully builds my 
program and links it with the VTK library.

Here is the CMakeLists.txt file:

cmake_minimum_required (VERSION 2.6)
project (fdtd-cuda-1)
find_package(VTK REQUIRED)
include( ${VTK_USE_FILE} )
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 vtkHybrid)

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 the makefile generated by cmake builds without problems on 
Ubuntu GNU/Linux, a similarly-generated makefile produces the following 
errors on Mac OS X.  It appears that CMake is finding the VTK library in 
the Python.framework directory in lieu of the one installed into 
/usr/local/lib.  Here are the errors produced on Mac OS X:

Matilda-2:FDTD-model-CUDA-1 nicholaskinar$ make
Linking CXX executable fdtd-cuda-1
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkHybrid.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkRendering.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkGraphics.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkverdict.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkImaging.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkftgl.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkfreetype.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkIO.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkFiltering.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkCommon.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkDICOMParser.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkmetaio.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtksqlite.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkpng.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtktiff.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkzlib.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkjpeg.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkexpat.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtksys.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkexoIIc.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
ld: warning: in 
/Library/Frameworks/Python.framework/Versions/6.1/lib/vtk-5.4/libvtkNetCDF.dylib, 
file was built for i386 which is not the architecture being linked (x86_64)
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 am I doing wrong here, and what should I change to ensure that 
CMake locates the proper version of VTK on Mac OS X?

Nicholas






More information about the vtkusers mailing list