ORB_SLAM记录

1 篇文章 0 订阅

1. 编译安装required libraries

1.1. pangolin

好久之前编译了一次,当时对cmake完全陌生【虽然现在依然如此】,跟着网上教程一点点做总是“不成功”【其实是差一步就成功了】,心灰意冷。隔了这么久,直到昨天把前面cmake-gui生成的project在vs中打开build,居然成功了。但是重新configure了vs版本后错误很多,这里记录一下过程。

用cmake-gui打开原来编译成功的pangolin项目显示的是“Current generator: Visual Studio 10”,但是打开项目确实自动选择了VS2013(机子上装了两个版本); 现在Delete Cache后点击配置没有该选项,如果选择“Visual Studio 10 2010”会自动用VS2010打开。相当怪异,可能cmake-gui版本不同造成的。

出错解决方法:
1.前一次选了VS2010没有成功,Delete Cache之后选了VS2013,因为前一次的cmake文件没有(delete cache)清楚干净,解决方法是最好删除所有生成的文件。

>CMake Error : error : generator : Visual Studio 12 2013
>  Does not match the generator used previously: Visual Studio 10 2010
>  Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.

2.build进行到关于“__libpng”这一步总是卡住(取消build要好久、不能删除build路径下external文件夹)或者出现错误找不到png.h,都可能因为“Performing download step (git clone) for ‘__libpng’”,貌似因为generator选择不正确。

3.“fatal error C1083: Cannot open include file: ‘unistd.h’: No such file or directory”,查看[网上教程][https://zhidao.baidu.com/question/917914344083732539.html],解决方法是手动添加一个unistd.h文件,但是仍然出现错误“error C3861: ‘mkfifo’: identifier not found;error C3861: ‘sleep’: identifier not found”,这个文件及其中声明的函数sleep和mkfifo应该都是Unix系统中的函数所以出错。幸好这里testlog需要include这个文件,貌似testlog不build不影响使用吧。

4.单独build install工程时,出现fetal error:

The command "setlocal "C:\Program Files\CMake\bin\cmake.exe" -DBUILD_TYPE=Debug -P cmake_install.cmake if %errorlevel% neq 0 goto :cmEnd :cmEnd endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone :cmErrorLevel exit /b %1 :cmDone if %errorlevel% neq 0 goto :VCEnd :VCEnd" exited with code 1.

c盘权限问题,可以以管理员身份运行(但有时候右键没有这个选项),需要在cmake_gui中configure时设置CMAKE_INSTALL_PREFIX设置安装路径其他安装路径。

5.错误CMake Error at Thirdparty/Pangolin/build/src/PangolinConfig.cmake:26 (set_target_properties): set_target_properties called with incorrect number of arguments.

set_target_properties(_libjpeg PROPERTIES
    IMPORTED_LOCATION E:/.../ORBSLAM24Windows-master/Thirdparty/Pangolin/build/external/libjpeg/lib/jpeg.lib
  )

6.打开pangolin整个项目编译example可以运行,但是单独打开一个example或者自己调用时,出现错误error LNK1104: cannot open file ‘_glew-NOTFOUND.obj’ C:\Users…\Documents\Visual Studio 2013\Projects\usepangolin\build\LINK

1.2 OpenCV

findpackage

1.3 Eigen3

不需要安装
查找到的文件设置include文件路径

1.4 g2o

Error 5 error C1083: Cannot open include file: ‘../../config.h’: No such file or directory c:\users\dan\desktop\orb_slam2_windows-master\orb_slam2_windows-master\thirdparty\g2o\g2o\core\openmp_mutex.h 30

int vasprintf(char **ptr, const char *format, va_list ap)
{
    int len;

    len = _vscprintf_p(format, ap) + 1;
    *ptr = (char *)malloc(len * sizeof(char));
    if (!*ptr)
    {
        return -1;
    }

    return _vsprintf_p(*ptr, len, format, ap);
}

Right click on the g2o project->Properties->C/C++->Preprocessor Definitions, add WINDOWS at the end row, click Apply and OK1.

其他一些细节

  1. target_link_library出错:2 An important detail is to place target_link_libraries after the add_executable and find_package lines, so all linked components are known.

Eigen3文件目录,不能把两个cmake文件和头文件放到同一个文件夹中

Eigen3-+
       |-Eigen3Config.cmake
       |-Eigen3Targets.cmake
       |-Eigen-+
               |-src
               |-...         

Eigen只有头文件,不需要编译3

Eigen doesn’t have any dependencies other than the C++ standard library. We use the CMake build system, but only to build the documentation and unit-tests, and to automate installation. If you just want to use Eigen, you can use the header files right away. There is no binary library to link to, and no configured header file. Eigen is a pure template library defined in the headers.

其中两个cmake文件可以用cmake-gui生成(只需要configure-generate即可,不需要打开build),在cmake-gui中如果没有自动找到Eigen位置,可手动设置Eigen3_DIR到Eigen3Config.cmake即Eigen3目录下。

两个*.cmake文件不是必须的:在当前项目路径下建立文件夹CMakeModules(一般是这样命名4,也可以用其他例如cmake_modules),其中添加FindEigen3.cmake,此文件随项目不同可稍有不同,主要是line 66设置查找路径:

    set(EIGEN_ADDITIONAL_SEARCH_PATHS "F:/.../Thirdparty/eigen" "C:/Program Files/Eigen/include" "C:/.../Eigen/include")

另外还需要在项目CMakeLists.txt中添加

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)#文件夹名称

尤其注意在FindEige3.cmake文件中的参数名称需要和CMakeLists.txt中参数名完全一致,例如

cmake_minimum_required(VERSION 2.8)
project(useEigen)
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
add_executable(useEigen main.cpp)
message("find_package之前:${EIGEN3_INCLUDE_DIR}")
find_package(Eigen3 REQUIRED)
message("find_package之后:${EIGEN3_INCLUDE_DIR}")
# set(EIGEN3_INCLUDE_DIRS ${Eigen3_DIR})#如果此时find_package失败,include文件也将查找失败
include_directories(${EIGEN3_INCLUDE_DIR})#曾把次参数写成EIGEN3_INCLUDE_DIRS导致打开的vs项目中include失败

cmake-gui输出结果:
cmake-gui输出结果

BUILD_SHARED_LIBS勾选

C++ internal complier error:
编绎文件时,出现这个问题原因一般就是内存不够,
若是在虚拟机上,关掉虚拟机,可直接调节虚拟机内存大小,然后重新启动即可。

‘usleep’ was not declared in this scope
try “#include unistd.h”5

2. 结果和讨论

2.1 速度

在VS中运行测试数据库,速度非常慢(难道是因为Debug模式运行?难道下载的ORBSLAM24Windows在速度方面存在缺陷?幸好在Ubuntu虚拟机上也编译成功,就先不再尝试编译windows的Release版本吧,专注于看程序)。在window上运行ORB_SLAM2最大的一个收获是对于CMake有了稍微深入一些的了解,在win上find_package总是出现问题,在解决问题的过程所中有所收获。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值