Dear All,
In my project, I am to run a VMTK c++ code using CMake. My setup are
【linux mint】+ 【gcc】+【visual studio code】+【cmake】, and first serveral lines of code are at the very bottom:
The problem I have is with CMakeLists.txt. To run the code, here are three ways I have tried:
【1】 I download the vmtk source code and build with CMake, and tree structure is as this
where include/vmtk and include/vtk-9.1 contain header files, and install/lib contains all the shared libs.
and CMakeLists.txt is as this
Blockquote
cmake_minimum_required(VERSION 3.0.0)
project(VMTK_TOY VERSION 0.1.0)
include(CTest)
enable_testing()
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
#/executable/
add_executable(${PROJECT_NAME} main.cpp)
#/headerfiles/
target_include_directories( ${PROJECT_NAME} PRIVATE XXX/vmtk-build/Install/include/vtk-9.1)
target_include_directories( ${PROJECT_NAME} PRIVATE XXX/vmtk-build/Install/include/vmtk )
#/vmtk shared libs/
set( VMTK_DIR “XXX/vmtk-build/Install/lib” )
target_link_libraries(${PROJECT_NAME} PRIVATE
${VMTK_DIR}/libvtkvmtkCommon.so
${VMTK_DIR}/libvtkvmtkComputationalGeometry.so
${VMTK_DIR}/libvtkvmtkContrib.so
${VMTK_DIR}/libvtkvmtkDifferentialGeometry.so
${VMTK_DIR}/libvtkvmtkIO.so
${VMTK_DIR}/libvtkvmtkITK.so
${VMTK_DIR}/libvtkvmtkMisc.so
${VMTK_DIR}/libvtkvmtkRendering.so
${VMTK_DIR}/libvtkvmtkSegmentation.so)
#/vtk shared libs/
find_package(VTK
COMPONENTS
CommonCore
CommonDataModel
CommonTransforms
FiltersCore
FiltersGeneral
FiltersGeometry
FiltersModeling
IOImage
IOXML
ImagingCore
ImagingStatistics
InteractionStyle
RenderingCore
RenderingVolume
RenderingOpenGL2
RenderingVolumeOpenGL2
OPTIONAL_COMPONENTS
TestingCore
TestingRendering)
target_link_libraries(${PROJECT_NAME} PRIVATE ${VTK_LIBRARIES})
then i got error like this.
collect2: error: ld returned 1 exit status
vtk shared libs part on this CMakelist.txt are copy and past from cmakelists.txt of a vtk example.
Then I realized that, this way, cmake might have linked to my other vtk-build (Which I have built years earlier, and stored at /usr/local/lib)
So I tried to link every single .so or .so.* files directly
【2】
Blockquote
cmake_minimum_required(VERSION 3.0.0)
project(VMTK_TOY VERSION 0.1.0)
include(CTest)
enable_testing()
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
add_executable(${PROJECT_NAME} main.cpp)
target_include_directories( ${PROJECT_NAME} PRIVATE XXX/vmtk-build/Install/include/vtk-9.1)
target_include_directories( ${PROJECT_NAME} PRIVATE XXX/vmtk-build/Install/include/vmtk )
target_link_directories( ${PROJECT_NAME} PRIVATE
XXX/vmtk-build/Install/lib/libITKBiasCorrection-5.2.so
XXX/vmtk-build/Install/lib/libITKBiasCorrection-5.2.so.1
XXX/vmtk-build/Install/lib/libITKColormap-5.2.so
…
)
basically, in target_link_directories, I listed every sinlge .so or .so.* files, in the directory
XXX/vmtk-build/install/lib
still, I got error like this
In fear of vmtk that I built may have flaws, I tried to install vmtk through anaconda
【3】
under
Blockquote
XXX/anaconda3/pkg
there are vmtk-1.4.0-py36**** and vtk-8.10-py36*** folders, both are like this
so I changed target_link_directories and target_include_directories in method【2】(without the rest changed)
to
Blockquote
target_include_directories( ${PROJECT_NAME} PRIVATE XXX/anaconda3/pkg/vtk-8.1.0-py36***/include/vtk-8.1)
target_include_directories( ${PROJECT_NAME} PRIVATE XXX/anaconda3/pkg/vmtk/include/vmtk )
target_link_directories( ${PROJECT_NAME} PRIVATE
XXX/anaconda3/pkg/vtk-8.1.0-py36***/lib/libITKBiasCorrection-5.2.so
XXX/anaconda3/pkg/vtk-8.1.0-py36***/lib/libITKBiasCorrection-5.2.so.1
XXX/anaconda3/pkg/vtk-8.1.0-py36***/lib/libITKColormap-5.2.so
…
)
and get the same error as 【1】
I have double checked every single path, and there is no typo on the paths.
So I doubt, the shared libs are still not linked in cmakelists.txt
On Windows 10, I tried this code using Visual Studio, it include headers and link .dll successfully, and the code runs well. Yet, I did not try running this code using CMake on Windows.
I researched on this issue for the whole weekend, but could not get a solution.
Please help me if you have any ideas or suggestions.
Thanks in advance!!!
Here is the c++ code.
Blockquote
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
#include <vtkSmartPointer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkJPEGReader.h>
#include <vtkCamera.h>
#include <vtkProperty.h>
#include <vtkAxesActor.h>
#include <vtkSTLReader.h>
#include <vtkDiscreteMarchingCubes.h>
#include <vtkWindowedSincPolyDataFilter.h>
#include <vtkCleanPolyData.h>
#include <vtkTriangleFilter.h>
#include <vtkPolyData.h>
#include <vtkPointData.h>
#include <vtkDataArray.h>
#include <vtkIdList.h>
#include <vtkDecimatePro.h>
#include <vtkDoubleArray.h>
#include <vtkParametricSpline.h>
#include <vtkParametricFunctionSource.h>
#include <vtkLODActor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkvmtkCapPolyData.h>
#include <vtkvmtkPolyDataCenterlines.h>
#include<vtkSTLWriter.h>
#include<vtkConeSource.h>
#include
#include
using namespace std;
int main()
{
string stl = “rightlumen.stl”;
vtkSmartPointer reader = vtkSmartPointer::New();
reader->SetFileName(stl.c_str());
reader->Update();
vtkSmartPointer data = vtkSmartPointer::New();
data->DeepCopy(reader->GetOutput());
return 0;
}