编译 ORB_SLAM2 (一)

      之前有记录关于ORB_SLAM的第一个版本的编译,每次就是要编译程序,都会遇到很多问题,并不是所谓的按照教程来就一定能编译成功,所以这一次编译也遇到了很多问题。百度的时候也看到网上有很多相似的问题,但是也有很多还没有解决的问题,恰好的我也遇到了,并且解决了。

  首先默认电脑环境ubuntu14.04和ROS indigo已经装好。  

      1. 安装Pangolin,用于可视化和用户接口

           git clone https://github.com/stevenlovegrove/Pangolin.git

           cd Pangolin

    mkdir build

    cd build

           cmake -DCPP11_NO_BOOST=1 ..

    make -j

如果出现Could NOT find GLEW错误 ,就是要安装一些依赖项

就是sudo apt-get install 以下这些依赖项

 libx11-dev libxmu-dev libglu1-mesa-dev libgl2ps-dev libxi-dev g++ libzip-dev libpng12-dev libcurl4-gnutls-dev libfontconfig1-dev libsqlite3-dev libglew*-dev libssl-dev

2.安装BLAS和LAPACK

sudo apt-get install libblas-dev
sudo apt-get install liblapack-dev

3 构建ORB_SLAM2库

git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
cd ORB_SLAM2
chmod +x build.sh
./build.sh

 问题(1)

   可能会出现在./build.sh 这一步,如果出现的错误大部分是跟openni.h和XnCppWrapper.h有关的话,请看这位大神的博客是可以解决问题的

www.cnblogs.com/liufuqiang/p/5618335.html

问题(2)

   如果在编译ORB_SLAM2时出现卡住的情况,无论怎么重新编译都会无法通过,网上也查不到关于卡住怎么办 的解决办法

http://tieba.baidu.com/p/4475718587就像这个贴吧里说的这样,只能ctrl+c,如如下图

如果编译的过程中卡住了 解决办法:把make -j   改为make -l,看一下make的用法:

Usage: make [options] [target] ...
Options:
  -b, -m                      Ignored for compatibility.
  -B, --always-make           Unconditionally make all targets.
  -C DIRECTORY, --directory=DIRECTORY
                              Change to DIRECTORY before doing anything.
  -d                          Print lots of debugging information.
  --debug[=FLAGS]             Print various types of debugging information.
  -e, --environment-overrides
                              Environment variables override makefiles.
  -f FILE, --file=FILE, --makefile=FILE
                              Read FILE as a makefile.
  -h, --help                  Print this message and exit.
  -i, --ignore-errors         Ignore errors from commands.
  -I DIRECTORY, --include-dir=DIRECTORY
                              Search DIRECTORY for included makefiles.
  -j [N], --jobs[=N]          Allow N jobs at once; infinite jobs with no arg.
  -k, --keep-going            Keep going when some targets can't be made.
  -l [N], --load-average[=N], --max-load[=N]
                              Don't start multiple jobs unless load is below N.
  -L, --check-symlink-times   Use the latest mtime between symlinks and target.
  -n, --just-print, --dry-run, --recon
                              Don't actually run any commands; just print them.
  -o FILE, --old-file=FILE, --assume-old=FILE
                              Consider FILE to be very old and don't remake it.
  -p, --print-data-base       Print make's internal database.
  -q, --question              Run no commands; exit status says if up to date.
  -r, --no-builtin-rules      Disable the built-in implicit rules.
  -R, --no-builtin-variables  Disable the built-in variable settings.
  -s, --silent, --quiet       Don't echo commands.
  -S, --no-keep-going, --stop
                              Turns off -k.
  -t, --touch                 Touch targets instead of remaking them.
  -v, --version               Print the version number of make and exit.
  -w, --print-directory       Print the current directory.
  --no-print-directory        Turn off -w, even if it was turned on implicitly.
  -W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE
                              Consider FILE to be infinitely new.
  --warn-undefined-variables  Warn when an undefined variable is referenced.
这样就编译成功,如图:

 4.编译生成ROS节点:根据read.md

       在 ~/.bashrc添加路径

                                  export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM2/Examples/ROS

   然后进入“Examples/ROS/ORB_SLAM2:执行

                                                                        mkdir build
                      cd build
                      cmake .. -DROS_BUILD_TYPE=Release
                      make -j

  可能出现的错误就是在  cmake .. -DROS_BUILD_TYPE=Release         如下图                        

意思是cv_bridge找不到opencv 的依赖项,即使把package.xml文件中的cv_bridge去除,虽然可以cmake成功,但是依赖项没有了。后面的make 也不能成功,

所以就把CMakefile.txt文件中

cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

rosbuild_init()

IF(NOT ROS_BUILD_TYPE)
  SET(ROS_BUILD_TYPE Release)
ENDIF()

MESSAGE("Build type: " ${ROS_BUILD_TYPE})

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()

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../../cmake_modules)

find_package(OpenCV 2.4.3 REQUIRED)
find_package(Eigen3 3.1.0 REQUIRED)
find_package(Pangolin REQUIRED)

include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/../../../
${PROJECT_SOURCE_DIR}/../../../include
${Pangolin_INCLUDE_DIRS}
)

set(LIBS 
${OpenCV_LIBS} 
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
)

# Node for monocular camera
rosbuild_add_executable(Mono
src/ros_mono.cc
)

target_link_libraries(Mono
${LIBS}
)

# Node for stereo camera
rosbuild_add_executable(Stereo
src/ros_stereo.cc
)

target_link_libraries(Stereo
${LIBS}
)

# Node for RGB-D camera
rosbuild_add_executable(RGBD
src/ros_rgbd.cc
)

target_link_libraries(RGBD
${LIBS}
)
View Code

改写为

cmake_minimum_required(VERSION 2.8.3)  #版本不同
project(orb_slam2)
find_package(catkin REQUIRED COMPONENTS
roscpp
sensor_msgs
image_transport
message_filters
cv_bridge
cmake_modules)

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()
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../../cmake_modules)
find_package(OpenCV 2.4.3 REQUIRED)
find_package(Eigen3 3.1.0 REQUIRED)
find_package(Pangolin REQUIRED)
catkin_package()
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/../../../
${PROJECT_SOURCE_DIR}/../../../include
${Pangolin_INCLUDE_DIRS}
)
set(LIBS
${catkin_LIBRARIES}
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
)
# Node for monocular camera
add_executable(mono
src/ros_mono.cc
)
target_link_libraries(mono
${LIBS}
)
# Node for RGB-D camera
add_executable(rgbd
src/ros_rgbd.cc
)
target_link_libraries(rgbd
${LIBS}
)
# Node for stereo camera
add_executable(stereo
src/ros_stereo.cc
)
target_link_libraries(stereo
${LIBS}
)

 把manifest.xml文件内容

<package>
  <description brief="ORB_SLAM2">

     ORB_SLAM2

  </description>
  <author>Raul Mur-Artal</author>
  <license>GPLv3</license>
  <depend package="roscpp"/>
  <depend package="tf"/>
  <depend package="sensor_msgs"/>
  <depend package="image_transport"/>
  <depend package="cv_bridge"/>


</package>

删除改为package.xml  内容为

<package>
<name>orb_slam2</name>
<version>0.0.1</version>
<description>ORB_SLAM2</description>
<author>Raul Mur-Artal</author>
<maintainer email="raulmur@unizar.es">Raul Mur-Artal</maintainer>
<license>GPLv3</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>tf</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>image_transport</build_depend>
<build_depend>message_filters</build_depend>
<build_depend>cv_bridge</build_depend>
<build_depend>cmake_modules</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>tf</run_depend>
<run_depend>sensor_msgs</run_depend>
<run_depend>image_transport</run_depend>
<run_depend>message_filters</run_depend>
<run_depend>cv_bridge</run_depend>
</package>

 就可以编译成功,如果出现卡住,仍然换成make -l

我只是记录下一些问题,大神请忽略

 

posted @ 2016-10-21 19:41  Being_young  阅读(5740)  评论(0编辑  收藏  举报