我在 Ubuntu 16 上使用 Qt Creator (Qt 5.8) 创建了一个新的 Qt 小部件应用程序。然后我创建了一个build/
和src/
文件夹并将所有创建的文件移动到该src/
文件夹中。接下来,我添加了这个CMakeLists.txt
文件并更改了构建设置,以便它使用 CMake。
cmake_minimum_required(VERSION 3.5)
project(PCLViewer3)
# init_qt: Let's do the CMake job for us
set(CMAKE_AUTOMOC ON) # For meta object compiler
set(CMAKE_AUTORCC ON) # Resource files
set(CMAKE_AUTOUIC ON) # UI files
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Find the QtWidgets library
find_package(Qt5 REQUIRED Widgets)
find_package(VTK REQUIRED)
#find_package(PCL 1.8.1 REQUIRED)
# Fix a compilation bug under ubuntu 16.04 (Xenial)
#list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
#include_directories(${PCL_INCLUDE_DIRS})
#link_directories(${PCL_LIBRARY_DIRS})
#add_definitions(${PCL_DEFINITIONS})
set(project_SOURCES main.cpp pclviewer.cpp)
add_executable(${PROJECT_NAME} ${project_SOURCES})
target_link_libraries(${PROJECT_NAME} ${PCL_LIBRARIES} Qt5::Widgets)
应用程序执行上述罚款CMakeLists.txt
。但是如果find_package(PCL 1.8.1 REQUIRED)
取消注释此行,则应用程序配置、生成和构建都很好,但执行错误如下:
Starting /home/dan/PCLViewer3/build/PCLViewer3...
*** Error in `/home/dan/PCLViewer3/build/PCLViewer3': realloc(): invalid pointer: 0x00007f01e9824820 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777f5)[0x7f01e83287f5]
/lib/x86_64-linux-gnu/libc.so.6(+0x85df0)[0x7f01e8336df0]
/lib/x86_64-linux-gnu/libc.so.6(realloc+0x24f)[0x7f01e833595f]
/home/dan/Qt5.8.0/5.8/gcc_64/lib/libQt5Core.so.5(_ZN9QListData12realloc_growEi+0x31)[0x7f01e8d15921]
/home/dan/Qt5.8.0/5.8/gcc_64/lib/libQt5Core.so.5(_ZN9QListData6appendEi+0x4f)[0x7f01e8d159bf]
/home/dan/Qt5.8.0/5.8/gcc_64/lib/libQt5Core.so.5(+0x1ce528)[0x7f01e8de1528]
/home/dan/Qt5.8.0/5.8/gcc_64/lib/libQt5Core.so.5(_Z21qRegisterResourceDataiPKhS0_S0_+0x2c3)[0x7f01e8ddcf73]
/home/dan/Qt5.8.0/5.8/gcc_64/lib/libQt5Core.so.5(+0x7d3b3)[0x7f01e8c903b3]
/lib64/ld-linux-x86-64.so.2(+0x106fa)[0x7f01ea0676fa]
...
7f01ea27d000-7f01ea27e000 rw-p 00026000 08:01 936331 /lib/x86_64-linux-gnu/ld-2.23.so
7f01ea27e000-7f01ea27f000 rw-p 00000000 00:00 0
7fffa88f3000-7fffa8914000 rw-p 00000000 00:00 0 [stack]
7fffa8919000-7fffa891c000 r--p 00000000 00:00 0 [vvar]
7fffa891c000-7fffa891e000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
The program has unexpectedly finished.
/home/dan/PCLViewer3/build/PCLViewer3 crashed.
我已经用这个文件尝试了点云库PCLwrite
中的示例,它执行得很好:CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(pcd_write)
# init_qt: Let's do the CMake job for us
set(CMAKE_AUTOMOC ON) # For meta object compiler
set(CMAKE_AUTORCC ON) # Resource files
set(CMAKE_AUTOUIC ON) # UI files
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_PREFIX_PATH "/home/dan/Qt5.8.0/5.8/gcc_64/lib/cmake/Qt5")
# Find the QtWidgets library
find_package(Qt5 REQUIRED Widgets)
find_package(VTK REQUIRED)
find_package(PCL 1.8.1 REQUIRED)
# Fix a compilation bug under ubuntu 16.04 (Xenial)
#list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (pcd_write pcd_write.cpp)
target_link_libraries (pcd_write ${PCL_LIBRARIES} Qt5::Widgets)
知道为什么find_package(PCL 1.8.1 REQUIRED)
会导致无效指针吗?我没有更改任何源代码...