Pangolin 是一个可用于SLAM可视化的openGL库。目前有很多SLAM系统都用它作为可视化的工具。它的编译与安装过程问题不大,依赖也比较少。但最近我在单独使用它的时候,碰到了很奇怪的现象:我单独将HelloPangolin这个example以及它的CMakelists.txt取出来,通过cmake,build的方式去编译,报了一堆错:
In file included from /home/lenovo/Pangolin/include/pangolin/var/var.h:34:0, from /home/lenovo/Pangolin/include/pangolin/var/varextra.h:31, from /home/lenovo/Pangolin/include/pangolin/pangolin.h:52, from /home/lenovo/expangolin/main.cpp:1: /home/lenovo/Pangolin/include/pangolin/var/varvalue.h: In instantiation of ‘void pangolin::VarValue::Init() [with T = bool]’: /home/lenovo/Pangolin/include/pangolin/var/varvalue.h:55:14: required from ‘pangolin::VarValue::VarValue(const T&) [with T = bool]’ /home/lenovo/Pangolin/include/pangolin/var/var.h:170:20: required from ‘pangolin::Var::Var(const string&, const T&, bool) [with T = bool; std::string = std::basic_string]’ /home/lenovo/Pangolin/include/pangolin/var/varextra.h:67:52: required from here /home/lenovo/Pangolin/include/pangolin/var/varvalue.h:99:23: error: ‘class pangolin::VarValue’ has no member named ‘str’ this->str = (VarValueTstd::string*)this; ^ /home/lenovo/Pangolin/include/pangolin/var/varvalue.h:102:23: error: ‘class pangolin::VarValue’ has no member named ‘str’ this->str = str_ptr;
出现这种错误,意味着Pangolin库的路径是能够被找到的,但通过这个库编译example的时候,出现了问题。这个问题困扰了很久,最终我通过对比ORB-SLAM2中的CMakeLists.txt才发现,需要通过CMake加上C++11 或者C++0x的support,最终编译pangolin的example的CMakeLists.txt 如下:
cmake_minimum_required(VERSION 2.8) project(HelloPangolin) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 -march=native ") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 -march=native") # Check C++11 or C++0x support include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) if(COMPILER_SUPPORTS_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") add_definitions(-DCOMPILEDWITHC11) message(STATUS "Using flag -std=c++11.") elseif(COMPILER_SUPPORTS_CXX0X) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") add_definitions(-DCOMPILEDWITHC0X) message(STATUS "Using flag -std=c++0x.") else() message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") endif() find_package(Pangolin REQUIRED) include_directories(${Pangolin_INCLUDE_DIRS}) # Build examples add_executable(test main.cpp) target_link_libraries(test ${Pangolin_LIBRARIES})
CMakeLists.txt
时间: 2024-12-06 20:28:58