ORB-SLAM2中build_ros.sh编译报错

ORB-SLAM2编译build_ros.sh报错
Building ROS nodes
mkdir: 无法创建目录 “build”: 文件已存在
CMake Warning (dev) in CMakeLists.txt:
No project() command is present. The top-level CMakeLists.txt file must
contain a literal, direct call to the project() command. Add a line of
code such as

project(ProjectName)

near the top of the file, but after cmake_minimum_required().

CMake is pretending there is a "project(Project)" command on the first
line.
This warning is for project developers. Use -Wno-dev to suppress it.

CMake Deprecation Warning at /opt/ros/noetic/share/ros/core/rosbuild/rosbuild.cmake:7 (cmake_policy):
The OLD behavior for policy CMP0011 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
CMakeLists.txt:2 (include)

CMake Deprecation Warning at /opt/ros/noetic/share/ros/core/rosbuild/rosbuild.cmake:16 (cmake_policy):
The OLD behavior for policy CMP0002 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
CMakeLists.txt:2 (include)

CMake Deprecation Warning at /opt/ros/noetic/share/ros/core/rosbuild/rosbuild.cmake:18 (cmake_policy):
The OLD behavior for policy CMP0003 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
CMakeLists.txt:2 (include)

CMake Deprecation Warning at /opt/ros/noetic/share/ros/core/rosbuild/rosbuild.cmake:20 (cmake_policy):
The OLD behavior for policy CMP0005 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
CMakeLists.txt:2 (include)

CMake Deprecation Warning at /opt/ros/noetic/share/ros/core/rosbuild/rosbuild.cmake:23 (cmake_policy):
The OLD behavior for policy CMP0011 will be removed from a future version
of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all
policies are deprecated and that a policy should be set to OLD only under
specific short-term circumstances. Projects should be ported to the NEW
behavior and not rely on setting a policy to OLD.
Call Stack (most recent call first):
CMakeLists.txt:2 (include)

[rosbuild] Building package ORB_SLAM2
Failed to invoke /opt/ros/noetic/bin/rospack deps-manifests ORB_SLAM2
Traceback (most recent call last):
File "/home/test/anaconda3/lib/python3.8/site-packages/rosdep2/init.py", line 40, in
from .installers import InstallerContext, Installer,
File "/home/test/anaconda3/lib/python3.8/site-packages/rosdep2/installers.py", line 36, in
from rospkg.os_detect import OsDetect
File "/home/test/anaconda3/lib/python3.8/site-packages/rospkg/os_detect.py", line 42, in
import distro
ModuleNotFoundError: No module named 'distro'
[rospack] Error: could not find python module 'rosdep2.rospack'. is rosdep up-to-date (at least 0.10.4)?

CMake Error at /opt/ros/noetic/share/ros/core/rosbuild/public.cmake:129 (message):

Failed to invoke rospack to get compile flags for package 'ORB_SLAM2'.
Look above for errors from rospack itself. Aborting. Please fix the
broken dependency!

Call Stack (most recent call first):
/opt/ros/noetic/share/ros/core/rosbuild/public.cmake:207 (rosbuild_invoke_rospack)
CMakeLists.txt:4 (rosbuild_init)

-- Configuring incomplete, errors occurred!
See also "/home/test/catkin_ws/src/ORB_SLAM2-master/Examples/ROS/ORB_SLAM2/build/CMakeFiles/CMakeOutput.log".

不知道你这个问题是否已经解决, 如果还没有解决的话:
  • 帮你找了个相似的问题, 你可以看下: https://ask.csdn.net/questions/779920
  • 这篇博客你也可以参考下:CMake error: error in configuration process, project files may be invalid 解决办法
  • 这篇博客也不错, 你可以看下CMake error: error in configuration process, project files may be invalid 解决办法
  • 除此之外, 这篇博客: Ubuntu18.04安装灭霸SLAM:ORBSLAM3中的 4.5 错误CMake Deprecation Warning at /opt/ros/melodic/share/ros/core/rosbuild/rosbuild.cmake:7 (cmake_policy): 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:
    Building ROS nodes
    mkdir: cannot create directory ‘build’: File exists
    CMake Deprecation Warning at /opt/ros/melodic/share/ros/core/rosbuild/rosbuild.cmake:7 (cmake_policy):
      The OLD behavior for policy CMP0011 will be removed from a future version
      of CMake.
    
      The cmake-policies(7) manual explains that the OLD behaviors of all
      policies are deprecated and that a policy should be set to OLD only under
      specific short-term circumstances.  Projects should be ported to the NEW
      behavior and not rely on setting a policy to OLD.
    Call Stack (most recent call first):
      CMakeLists.txt:2 (include)
    
    
    CMake Deprecation Warning at /opt/ros/melodic/share/ros/core/rosbuild/rosbuild.cmake:16 (cmake_policy):
      The OLD behavior for policy CMP0002 will be removed from a future version
      of CMake.
    
      The cmake-policies(7) manual explains that the OLD behaviors of all
      policies are deprecated and that a policy should be set to OLD only under
      specific short-term circumstances.  Projects should be ported to the NEW
      behavior and not rely on setting a policy to OLD.
    Call Stack (most recent call first):
      CMakeLists.txt:2 (include)
    
    
    CMake Deprecation Warning at /opt/ros/melodic/share/ros/core/rosbuild/rosbuild.cmake:18 (cmake_policy):
      The OLD behavior for policy CMP0003 will be removed from a future version
      of CMake.
    
      The cmake-policies(7) manual explains that the OLD behaviors of all
      policies are deprecated and that a policy should be set to OLD only under
      specific short-term circumstances.  Projects should be ported to the NEW
      behavior and not rely on setting a policy to OLD.
    Call Stack (most recent call first):
      CMakeLists.txt:2 (include)
    
    
    CMake Deprecation Warning at /opt/ros/melodic/share/ros/core/rosbuild/rosbuild.cmake:20 (cmake_policy):
      The OLD behavior for policy CMP0005 will be removed from a future version
      of CMake.
    
      The cmake-policies(7) manual explains that the OLD behaviors of all
      policies are deprecated and that a policy should be set to OLD only under
      specific short-term circumstances.  Projects should be ported to the NEW
      behavior and not rely on setting a policy to OLD.
    Call Stack (most recent call first):
      CMakeLists.txt:2 (include)
    
    
    CMake Deprecation Warning at /opt/ros/melodic/share/ros/core/rosbuild/rosbuild.cmake:23 (cmake_policy):
      The OLD behavior for policy CMP0011 will be removed from a future version
      of CMake.
    
      The cmake-policies(7) manual explains that the OLD behaviors of all
      policies are deprecated and that a policy should be set to OLD only under
      specific short-term circumstances.  Projects should be ported to the NEW
      behavior and not rely on setting a policy to OLD.
    Call Stack (most recent call first):
      CMakeLists.txt:2 (include)
    
    
    [rosbuild] Building package ORB_SLAM3
    Failed to invoke /opt/ros/melodic/bin/rospack deps-manifests ORB_SLAM3
    Traceback (most recent call last):
      File "/usr/lib/python2.7/dist-packages/rosdep2/rospack.py", line 60, in init_rospack_interface
        lookup = _get_default_RosdepLookup(Options())
      File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 136, in _get_default_RosdepLookup
        verbose=options.verbose)
      File "/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py", line 609, in create_default
        sources = load_cached_sources_list(sources_cache_dir=sources_cache_dir, verbose=verbose)
      File "/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py", line 566, in load_cached_sources_list
        raise CachePermissionError('Failed to write cache file: ' + str(e))
    rosdep2.core.CachePermissionError: Failed to write cache file: [Errno 13] Permission denied: '/home/nvidia/.ros/rosdep/sources.cache/index'
    [rospack] Error: could not call python function 'rosdep2.rospack.init_rospack_interface'
    
    
    CMake Error at /opt/ros/melodic/share/ros/core/rosbuild/public.cmake:129 (message):
      
    
      Failed to invoke rospack to get compile flags for package 'ORB_SLAM3'.
      Look above for errors from rospack itself.  Aborting.  Please fix the
      broken dependency!
    
    Call Stack (most recent call first):
      /opt/ros/melodic/share/ros/core/rosbuild/public.cmake:207 (rosbuild_invoke_rospack)
      CMakeLists.txt:4 (rosbuild_init)
    
    
    -- Configuring incomplete, errors occurred!
    See also "/home/nvidia/ORB_SLAM3/catkin_ws/src/ORB_SLAM3-v0.3-beta/Examples/ROS/ORB_SLAM3/build/CMakeFiles/CMakeOutput.log".
    make: *** No targets specified and no makefile found.  Stop.
    
    

    这个错误的原因时因为,没有写入环境变量里面,但是写入后同时也报这个错误,那么需要rosdep一下,推荐使用鱼香ros的rosdep方法。

    最简单的ROS安装方法和rosdepc安装(一行代码搞定)
    具体方法是:
    curl http://fishros.com/tools/install/rosdepc | bash 
    
    sudo rosdep fix-permissions
    rosdep update
    

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^