[vtkusers] Question about VKT installation

John Drescher drescherjm at gmail.com
Sun Aug 3 10:54:05 EDT 2008


2008/8/3 HayamiSanjuro <sanjurohayami at hotmail.com>:
> Hi all,
>
> I am a newb of VTK, I ame going to do a project by using Visual studio 2008
> and VTK. So I downloaded and set the VTK source by CMAKE and generated the
> VTK.sln. After that I compiled the VTK project by using VS 2008 and built
> the INSTALL project. I also added the
> VS->Tools->Options->VC++Directories->Include file "<my install
> path>/include/vtk-5.0" and added the
> VS->Tools->Options->VC++Directories->Library file "<my install path>\lib".
>
> But when I tried to declare a vtkPoints pointer variable,
>
> #include <vtkPoints.h>
> ...
> void DrawDelaunay2D()
> {
>   vtkPoints *pts = vtkPoints::New();
> }
> ...
>
> I still get an link error message:
>
> 1>Stroke.obj : error LNK2019: unresolved external symbol "public: static
> class vtkPoints * __cdecl vtkPoints::New(void)" (?New at vtkPoints@@SAPAV1 at XZ)
> referenced in function "public: void __thiscall Stroke::processStroke(void)"
> (?processStroke at Stroke@@QAEXXZ)
> 1>C:\Documents and Settings\Rong\My Documents\Visual Studio
> 2008\Projects\LifeSketch\Debug\LifeSketch.exe : fatal error LNK1120: 1
> unresolved externals
>
> Can any1 plz tell me whats wrong with the installation or anyother thing
> might cause the error.
>
> I tried to check the mailing list, there was a guy facing similary problem
> and asked in Jun 2004 but there was no answer for his question.
>

A quick fix would be probably to modify the .sln file to link with
vtkCommon but in my opinion this is the wrong approach.

If you use CMake to generate your project files you should never edit
your generated project files directly for several reasons. And never
add files to your generated projects. One reason is running CMake
again will wipe out all of the changes you did. Edit the
CMakeLists.txt file instead. A second reason is that if you do not
keep your CMakeLists.txt file current you will loose the ability to
use it to generate a project file different compiler / operating
system.

Here is an example CMakeLists.txt of a project I am working on (that
uses ITK, VTK, Qt and boost in windows and in linux):

PROJECT(LungAnalysis)

IF(WIN32)
    CMAKE_MINIMUM_REQUIRED(VERSION 2.5 FATAL_ERROR)
    SET(CMAKE_CXX_FLAGS "/WL /GR /EHsc" )
ENDIF(WIN32)

ADD_DEFINITIONS(-DNEED_WL_FILTER)
#ADD_DEFINITIONS(-DNEED_SHIFT_SCALE_FILTER)

IF(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

SET (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
"Single output directory for building all libraries.")
SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE INTERNAL
"Single output directory for building all executables.")

FIND_PACKAGE( Boost REQUIRED )
FIND_PACKAGE( Qt4 REQUIRED )
FIND_PACKAGE( ITK REQUIRED )
FIND_PACKAGE( VTK REQUIRED )
#FIND_PACKAGE( WrapITK  REQUIRED )

INCLUDE( ${ITK_USE_FILE} )
INCLUDE( ${VTK_USE_FILE} )

FIND_PATH(ITK_VTK_GLUE_DIR "CMakeLists.txt" PATHS
${ITK_SOURCE_DIR}/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue)
INCLUDE_DIRECTORIES(${ITK_VTK_GLUE_DIR}/src)

INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} . Include)

INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} )

INCLUDE( ${QT_USE_FILE} )
SET( UPMC_LA_SRCS
        ./src/main.cxx
        ./src/mainwindow.cxx
        ./src/textwidget.cxx
        ./src/VTK2dWidget.cpp
    ./src/itkQtProgressBar.cxx
    ./src/ImageSliceViewer.cxx
    ./src/DicomImageReaderBase.cxx
    ./src/InteractorObserver.cxx
    ./src/GenericVTKViewer.cxx
    ./src/upmcView.cxx
    ./src/upmcDocument.cxx
    ./src/upmcDocumentMgr.cxx
  )

SET( UPMC_LA_MOC_HDR
        ./Include/mainwindow.h
        ./Include/textwidget.h
        ./Include/VTK2dWidget.h
        ./Include/itkQtAdaptor.h
        ./Include/itkQtLightIndicator.h
        ./Include/itkQtProgressBar.h
        ./Include/upmcView.h
        ./Include/upmcDocument.h
        ./Include/upmcDocumentMgr.h
)

SET( UPMC_LA_HDRS
        ./Include/ImageSliceViewer.h
        ./Include/DicomSeries.h
        ./Include/DicomSeries.txx
        ./Include/DicomSeriesBase.h
        ./Include/DicomSeriesBase.txx
        ./Include/DicomImageReader.h
        ./Include/DicomImageReader.txx
        ./Include/DicomImageReaderBase.h
        ./Include/InteractorObserver.h
        ./Include/ClickedPointEvent.h
        ./Include/GenericVTKViewer.h
)

# some .ui files
SET( UPMC_LA_UIS
        ./rc/vtk2dWidget.ui
)

# and finally an resource file
SET( UPMC_LA_RCS
        ./rc/LungAnalysis.qrc
)

# this command will generate rules that will run rcc on all files from
UPMC_LA_RCS
# in result UPMC_LA_RC_SRCS variable will contain paths to files produced by rcc
QT4_ADD_RESOURCES( UPMC_LA_RC_SRCS ${UPMC_LA_RCS} )

# and finally this will run moc:
QT4_WRAP_CPP( UPMC_LA_MOC_SRCS ${UPMC_LA_MOC_HDR} )

# this will run uic on .ui files:
QT4_WRAP_UI( UPMC_LA_UI_HDRS ${UPMC_LA_UIS} )

LINK_LIBRARIES ( LungAnalysis ${QT_LIBRARIES} ITKCommon
ITKBasicFilters ITKIO QVTK vtkCommon
)

ADD_EXECUTABLE( LungAnalysis ${UPMC_LA_SRCS} ${UPMC_LA_MOC_SRCS} ${UPMC_LA_HDRS}
${UPMC_LA_MOC_HDR} ${UPMC_LA_RC_SRCS} ${UPMC_LA_UI_HDRS}
)


John



More information about the vtkusers mailing list