系统版本:Ubuntu16.04
问题描述:
刚开始跟着PCL tutorials官方教程学习PCL点云库,先创建pcd_write.cpp文件,然后编写CMakeLists.txt文件,官方提供的CMakeLists.txt文件内容如下:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(pcd_write)
find_package(PCL 1.2 REQUIRED)
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})
编译:
在当前目录下打开终端并进行cmake编译,
mkdir build
cd build
cmake ..
make
编译后报如下错误:
error: ISO C++ forbids declaration of ‘point’ with no type [-fpermissive]
for (auto& point: cloud)
warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11
for (auto& point: cloud)
error: request for member ‘y’ in ‘point’, which is of non-class type ‘int’
point.y = 1024 * rand () / (RAND_MAX + 1.0f);
error: request for member ‘y’ in ‘point’, which is of non-class type ‘int’
point.y = 1024 * rand () / (RAND_MAX + 1.0f);
error: request for member ‘z’ in ‘point’, which is of non-class type ‘int’
point.z = 1024 * rand () / (RAND_MAX + 1.0f);
解决方案:
从第二句warning的警告可以知道基于范围的for循环仅适用于-std=c++11 或?-std=gnu++11标准,因此需要在CMakeLists.txt文件中加入C++11标准,最终的CMakeLists.txt文件内容如下:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
# 指定为C++11 标准
set(CMAKE_CXX_STANDARD 11)
project(pcd_write)
find_package(PCL 1.2 REQUIRED)
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})
接下来就可以顺利通过编译了。
|