I'm learning slam recently, and setting up the environment is really a headache. It takes half a day to install each library. In the last fourteen lectures, the routines still can't be run. I don't know if the library is not installed properly or because the version is inconsistent or the makefile is not written properly.
So I was looking for routines after recent installation. First, I tried to see if each library was installed successfully.
Before the installation, there are: Installing the Pangolin library on ubuntu16.04_Qianmengyu 11's blog-CSDN blog
The verification uses Pangolin’s own routine: Pangolin/examples/HelloPangolin folder
1. Enter the corresponding folder on the terminal:
cd Pangolin
cd examples/HelloPangolin
2. One-stop compilation and operation:
cmake .
make
./HelloPangolin
Of course, this is the ideal situation. If you encounter an error during the make process:
/usr/local/include/pangolin/var/varextra.h:68:52: required from here
/usr/local/include/pangolin/var/varvalue.h:100:23: error: ‘class pangolin::VarValue<bool>’ has no member named ‘str’
this->str = (VarValueT<std::string>*)this;
^
/usr/local/include/pangolin/var/varvalue.h:103:23: error: ‘class pangolin::VarValue<bool>’ has no member named ‘str’
this->str = str_ptr;
^
CMakeFiles/HelloPangolin.dir/build.make:75: recipe for target 'CMakeFiles/HelloPangolin.dir/main.o' failed
make[2]: *** [CMakeFiles/HelloPangolin.dir/main.o] Error 1
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/HelloPangolin.dir/all' failed
make[1]: *** [CMakeFiles/HelloPangolin.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
This is a problem with CMakeLists.txt, mainly related to standard support and other issues. You need to add:
# 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()
Finally the entire CMakeLists.txt should be:
# Find Pangolin (https://github.com/stevenlovegrove/Pangolin)
find_package(Pangolin 0.4 REQUIRED)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(HelloPangolin main.cpp)
target_link_libraries(HelloPangolin ${Pangolin_LIBRARIES})
# 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()
Many solutions are to simply change the set (CMAKE_CXX_STANDARD 11), but it has never worked. This is a bit complicated, but it can be done. If it doesn't work, try this.
The result is: