2

是否可以使用 qt5 和 vtk 6.3(或主干版本)构建 qvtk 库(和亲属)?

我从 .run 安装程序安装了 qt5,一切都安装得很好,然后我从启用 VTK_Group_Qt 并正确设置 qt 路径的源构建了 vtk 6.3。

QVTK(qt 的 VTK 小部件)似乎没有任何特定的选项或模块,所以我假设它是用这个配置构建的,但是当我尝试编译一些依赖于 QVTK 的源代码时,我得到了错误:

/usr/bin/ld: cannot find -lvtkRendering
/usr/bin/ld: cannot find -lvtkGraphics
/usr/bin/ld: cannot find -lvtkHybrid
/usr/bin/ld: cannot find -lQVTK

有没有办法从 VTK 主干构建这些库?我在任何地方都找不到任何迹象。

4

2 回答 2

2

我为这个问题苦苦挣扎了很长时间,结果发现这是项目的 CMakeLists.txt 的问题。

我将在此处为遇到相同问题的任何人发布错误和正确的版本:

错误的:

cmake_minimum_required (VERSION 2.6 FATAL_ERROR)

project      (pcl-visualizer)
find_package (Qt5Wodgets)
find_package (VTK REQUIRED)
find_package (PCL 1.8 REQUIRED)

include_directories (${PCL_INCLUDE_DIRS})
link_directories    (${PCL_LIBRARY_DIRS})
add_definitions     (${PCL_DEFINITIONS})

set  (project_SOURCES main.cpp pclviewer.cpp)
set  (project_HEADERS pclviewer.h)
set  (project_FORMS   pclviewer.ui)
set  (VTK_LIBRARIES   vtkRendering vtkGraphics vtkHybrid QVTK)

QT5_WRAP_CPP (project_HEADERS_MOC   ${project_HEADERS})
QT5_WRAP_UI  (project_FORMS_HEADERS ${project_FORMS})

ADD_DEFINITIONS (${QT_DEFINITIONS})

ADD_EXECUTABLE  (pcl_visualizer ${project_SOURCES}
                                ${project_FORMS_HEADERS}
                                ${project_HEADERS_MOC})

TARGET_LINK_LIBRARIES (pcl_visualizer ${PCL_LIBRARIES} ${VTK_LIBRARIES} ${QT_LIBRARIES})

正确的:

cmake_minimum_required (VERSION 2.6 FATAL_ERROR)

project      (pcl-visualizer)
find_package (Qt5 REQUIRED COMPONENTS Widgets Core)
find_package (VTK REQUIRED)
find_package (PCL 1.8 REQUIRED)

include_directories (${PCL_INCLUDE_DIRS})
link_directories    (${PCL_LIBRARY_DIRS})
add_definitions     (${PCL_DEFINITIONS})

set  (project_SOURCES main.cpp pclviewer.cpp)
set  (project_HEADERS pclviewer.h)
set  (project_FORMS   pclviewer.ui)

QT5_WRAP_CPP (project_HEADERS_MOC   ${project_HEADERS})
QT5_WRAP_UI  (project_FORMS_HEADERS ${project_FORMS})

ADD_DEFINITIONS (${QT_DEFINITIONS})

ADD_EXECUTABLE  (pcl_visualizer ${project_SOURCES}
                                ${project_FORMS_HEADERS}
                                ${project_HEADERS_MOC})

TARGET_LINK_LIBRARIES (pcl_visualizer ${PCL_LIBRARIES})

qt5_use_modules (pcl_visualizer Widgets)

我不是 100% 确定问题的原因,但我的猜测是 libQVTK 等在 qt5 中被 Qt5Widgets 模块替换(我想知道它指的是哪些库),使得旧库不可用且不需要。

于 2015-10-13T12:28:47.153 回答
0

你可能想看看这个。在 VTK 的“CMakeLists.txt”中:

IF (VTK_USE_QT AND VTK_USE_GUISUPPORT AND VTK_USE_RENDERING)
  SET (VTK_USE_QVTK ON CACHE INTERNAL "Build QVTK widget and plugin for Qt" FORCE)
ELSE (VTK_USE_QT AND VTK_USE_GUISUPPORT AND VTK_USE_RENDERING)
  SET (VTK_USE_QVTK OFF CACHE INTERNAL "Build QVTK widget and plugin for Qt" FORCE)
ENDIF (VTK_USE_QT AND VTK_USE_GUISUPPORT AND VTK_USE_RENDERING)

因此,在构建 VTK 时,您应该打开 VTK_USE_QTVTK_USE_GUISUPPORT和。VTK_USE_RENDERING ON(最后一个应该默认打开)话虽如此,版本 5.10.1 的“CMakeLists.txt”可能需要一些编辑才能链接到 Qt5。

于 2016-04-04T03:57:41.517 回答