我为这个问题苦苦挣扎了很长时间,结果发现这是项目的 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 模块替换(我想知道它指的是哪些库),使得旧库不可用且不需要。