0

I'm using VTK to read a DICOM series. I can compile (using CMake) VTK example code and it runs well. Now, I'm trying to use Qtcreator and Qt4.8.5 to create a GUI. I have linked the library and include path on project.pro.

When I build, I get:

Undefined symbols:
  "vtkImageViewer2::New()", referenced from:
     vtkSmartPointer<vtkImageViewer2>::New()        in mainwindow.o
ld: symbol(s) not found

I checked, the Include path, and it includes /usr/local/vtk-6.1/include/vtk-6.1/ which contains vtkImageViewer2.h.

What's wrong with my project?

David Doria
  • 9,873
  • 17
  • 85
  • 147
Nicolaus
  • 3
  • 2

2 Answers2

1

That is a linker error, so your project is indeed finding vtkImageViewer2.h correctly. You should use CMake to create your project, then you can simply do

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

and all of the VTK linking will be taken care of for you.

David Doria
  • 9,873
  • 17
  • 85
  • 147
  • thanks for the edit, I'm going to compile it using cmake.. anyway, is there any solution so that I can use qt for compile the program? I was following tutorial about "Displaying DICOM series" [HERE THE LINK](http://hxr99.blogspot.com/2013/03/qt-vtk-displaying-dicom-series-using.html) is my vtk version could be the problem for linking? – Nicolaus May 26 '14 at 11:36
  • CMake does not compile anything, it just creates a "project" (this could be Visual Studio, Eclipse, etc.). In your case, creating the default project, a "Unix" project, will create standard Make files that could be used to compile with 'make' from a terminal. Better than that, however, is that you can simply open the CMakeLists.txt file from QtCreator and it will create a QtCreator project for you. This is the process that I typically use in my work. To answer your question, I don't think it is a VTK version problem, but using CMake like this should definitely prevent that from being an issue. – David Doria May 27 '14 at 12:06
  • thanks for sharing david it's very helpful, i use cmake for creating the project now – Nicolaus May 29 '14 at 18:49
0

As an addendum to David's answer, do not forgot to add ${VTK_LIBRARIES} (defined by the VTK Use file) to your library or binary/executable:

TARGET_LINK_LIBRARIES(myLib ${VTK_LIBRARIES})

and the paths to the libraries as:

link_directories(${VTK_LIBRARY_DIRS})
shakes76
  • 21
  • 3