环境搭建、代码编译错误提示合集

环境搭建错误提示合集

  • TX2环境搭建
    • 安装Pangolin
    • 编译yunchih-ORB-SLAM2-GPU2016-final
      • 错误1(cuda库找不到)
      • 错误2(当前opencv版本不支持cuda)
      • 编译ros节点
    • 其他错误
      • c++ error:unrecognized command line option '-msse'
    • 安装pytorch时:Failed cleaning build dir for numpy
  • ubuntu18.04环境搭建
    • ROS安装过程被中断
      • 缺少依赖
      • 无法rosdep init
        • 方法一
        • 方法二
  • 编译出错
      • PluginlibFactory: The plugin for class ‘grid_map_rviz_plugin/GridMap‘ failed to load
      • 编译过程中出现找不到.cmake文件的错误

TX2环境搭建

安装Pangolin

参看软件包中的README,需要安装一些依赖,主要是

sudo apt-get install libglew-dev

如果出现无法定位包,那么更新国内的源

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main restricted universe multiverse  
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main restricted universe multiverse   
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main restricted universe multiverse   
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main restricted universe multiverse   
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main restricted universe multiverse   
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main restricted universe multiverse   
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main universe restricted   
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main universe restricted

在make -j中出现如下错误

/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmFreeDevice'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libEGL.so: undefined reference to `drmGetNodeTypeFromFd'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libEGL.so: undefined reference to `drmGetRenderDeviceNameFromFd'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmFreeDevices'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmMap'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmGetDeviceNameFromFd2'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmCloseOnce'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmUnmap'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmGetDevices2'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmOpenOnce'
/usr/lib/gcc/aarch64-linux-gnu/5/../../../aarch64-linux-gnu/libGL.so: undefined reference to `drmGetDevice2'
collect2: error: ld returned 1 exit status
tools/VideoViewer/CMakeFiles/VideoViewer.dir/build.make:108: recipe for target 'tools/VideoViewer/VideoViewer' failed
make[2]: *** [tools/VideoViewer/VideoViewer] Error 1
CMakeFiles/Makefile2:289: recipe for target 'tools/VideoViewer/CMakeFiles/VideoViewer.dir/all' failed
make[1]: *** [tools/VideoViewer/CMakeFiles/VideoViewer.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

需要重新创建对应libGL.so的软连接,这里可能是X86和arm64的ubuntu系统版本问题,默认路径有差异.执行下面指令

cd /usr/lib/aarch64-linux-gnu
sudo rm libGL.so
sudo ln -s /usr/lib/aarch64-linux-gnu/tegra/libGL.so libGL.so

同样的,如果出现错误


/usr/lib/aarch64-linux-gnu/libEGL.so: undefined reference to `drmFreeDevice'
/usr/lib/aarch64-linux-gnu/libEGL.so: undefined reference to `drmGetNodeTypeFromFd'
/usr/lib/aarch64-linux-gnu/libEGL.so: undefined reference to `drmGetRenderDeviceNameFromFd'
/usr/lib/aarch64-linux-gnu/libEGL.so: undefined reference to `drmFreeDevices'
/usr/lib/aarch64-linux-gnu/libEGL.so: undefined reference to `drmGetDevices2'
/usr/lib/aarch64-linux-gnu/libEGL.so: undefined reference to `drmGetDevice2'

则继续执行下面指令

cd /usr/lib/aarch64-linux-gnu
sudo rm libEGL.so
sudo ln -s /usr/lib/aarch64-linux-gnu/tegra-egl/libEGL.so libEGL.so

编译yunchih-ORB-SLAM2-GPU2016-final

这是用GPU加速的ORBSLAM2源码,编译时由于环境原因市场会出错

错误1(cuda库找不到)

../lib/libORB_SLAM2_CUDA.so: undefined reference to cv::cuda::createGaussianFilter(int, int, cv::Size_, double, double, int, int)' ../lib/libORB_SLAM2_CUDA.so: undefined reference to cv::cuda::copyMakeBorder(cv::_InputArray const&, cv::OutputArray const&, int, int, int, int, int, cv::Scalar, cv::cuda::Stream&)'
../lib/libORB_SLAM2_CUDA.so: undefined reference to cv::cuda::resize(cv::_InputArray const&, cv::OutputArray const&, cv::Size, double, double, int, cv::cuda::Stream&)' ../lib/libORB_SLAM2_CUDA.so: undefined reference to cv::cuda::StreamAccessor::wrapStream(CUstream_st*)'
collect2: error: ld returned 1 exit status
CMakeFiles/rgbd_tum.dir/build.make:162: recipe for target 'rgbd_tum' failed
make[2]: *** [rgbd_tum] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/rgbd_tum.dir/all' failed
make[1]: *** [CMakeFiles/rgbd_tum.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

修改CMakeLists文件

target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so
nvToolsExt
)

改为

target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so
nvToolsExt
opencv_cudabgsegm
opencv_cudaobjdetect
opencv_cudastereo
opencv_cudafeatures2d
opencv_cudacodec
opencv_cudaoptflow
opencv_cudalegacy
opencv_cudawarping
opencv_cudaimgproc
opencv_cudafilters
)

错误2(当前opencv版本不支持cuda)

OpenCV Error: No CUDA support (The library is compiled without CUDA support) in throw_no_cuda, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/include/opencv2/core/private.cuda.hpp, line 107
terminate called after throwing an instance of 'cv::Exception'
  what():  /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/core/include/opencv2/core/private.cuda.hpp:107: error: (-216) The library is compiled without CUDA support in function throw_no_cuda

这是由于ros自带的opencv3.3.1是不带cuda加速的,而在编译过程中CMakeLists中查找的opencv库是3.3的所以需要该一下这里的版本成为已经安装支持cuda接口的版本号,我这里是3.4.1,所以改为3.4.1

其中为了避免工程调用ros下的opencv,那么在使用cuda的算法CMakeLists文件必须添加opencv版本,这里我使用3.4.1,这是自己在已有ros的3.3.1版本基础下另装的
把下面的命令复制到CMakeLists文件

find_package(OpenCV 3.4.1 REQUIRED
NO_MODULE 
PATHS /usr/local
NO_DEFAULT_PATH) #make sure not doesn't link to ROS OpenCV version

编译ros节点

这里的CMakeListst文件需要进行修改

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

set (CMAKE_CXX_STANDARD 11)

rosbuild_init()

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

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

include(FindOpenMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS} -Wall  -O3 ") #-march=native ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -Wall  -O3") # -march=native")
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

# Check C++11 or C++0x support
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
add_definitions(-DCOMPILEDWITHC11)
message(STATUS "Using flag -std=c++11.")


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

find_package(OpenCV 3.4.1 REQUIRED
NO_MODULE 
PATHS /usr/local
NO_DEFAULT_PATH) #make sure not doesn't link to ROS OpenCV version
find_package(Eigen3 REQUIRED)
find_package(Pangolin REQUIRED)

message(STATUS ${OpenCV_INCLUDE_DIRS})
message(STATUS ${CUDA_INCLUDE_DIRS})

find_package(CUDA QUIET REQUIRED)
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
SET(CUDA_HOST_COMPILER /usr/bin/g++)
LIST(APPEND CUDA_NVCC_FLAGS "--compiler-options -fno-strict-aliasing -use_fast_math")


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

nvToolsExt
)

cuda_include_directories(
  ${CUDA_TOOLKIT_ROOT_DIR}/samples/common/inc
)

cuda_add_library(${PROJECT_NAME} SHARED
../../../src/System.cc
../../../src/Tracking.cc
../../../src/LocalMapping.cc
../../../src/LoopClosing.cc
../../../src/ORBextractor.cc
../../../src/ORBmatcher.cc
../../../src/FrameDrawer.cc
../../../src/Converter.cc
../../../src/MapPoint.cc
../../../src/KeyFrame.cc
../../../src/Map.cc
../../../src/MapDrawer.cc
../../../src/Optimizer.cc
../../../src/PnPsolver.cc
../../../src/Frame.cc
../../../src/KeyFrameDatabase.cc
../../../src/Sim3Solver.cc
../../../src/Initializer.cc
../../../src/Viewer.cc
../../../src/cuda/Allocator_gpu.cu
../../../src/cuda/Fast_gpu.cu
../../../src/cuda/Orb_gpu.cu
../../../src/cuda/Cuda.cu
)

set(LIBS 

${OpenCV_LIBS} 
${CUDA_LIBRARIES}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../build/lib/libORB_SLAM2.so
-lboost_system
opencv_cudabgsegm
opencv_cudaobjdetect
opencv_cudastereo
opencv_cudafeatures2d
opencv_cudacodec
opencv_cudaoptflow
opencv_cudalegacy
opencv_cudawarping
opencv_cudaimgproc
opencv_cudafilters
)



# 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}
)

其他错误

c++ error:unrecognized command line option ‘-msse’

这种情况是因为在arm平台上不存在SSE指令集的,在X86平台才会有,因此需要在CMakLists文件中吧有关-msse3字样的都注释掉

# arm and intel cpu configurations
#IF(DEFINED ENV{ARM_ARCHITECTURE})
#  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon -march=armv7-a")
#ELSE()
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse -msse2 -march=native")
#ENDIF()

安装pytorch时:Failed cleaning build dir for numpy

在TX2安装Pytorch的时候是通过pip3 install命令对whl文件进行安装的

pip3 install numpy torch-1.1.0-cp36-cp36m-linux_aarch64.whl --user

可能会出现标题的错误
解决方法

sudo apt-get install python3.6-dev

由于需要python3.6*版本安装,所以要安装对应3.6的包
这里通过whl直接安装的torch是依赖于cuda10.0的,所以非cuda10.0的环境即便显示安装通过通过指令
import torch
会出现错误

ImportError: libcusparse.so.10.0: cannot open shared object file: No such file or directory

并且在编译依赖torch的工程时也会出现找不到 .os.10.0 库的提示,所以jetson系列还是得是jetpack4.2版本且安装cuda10.0的才能通过这指令安装且不出现后遗症

ubuntu18.04环境搭建

ROS安装过程被中断

缺少依赖

比如在安装ros过程中,因为缺少某些依赖,在进行到某一步的时候出现安装中断,可以执行下面命令,可以自行安装需要的依赖完成接下来的安装环境搭建、代码编译错误提示合集_第1张图片

sudo apt --fix-broken install

环境搭建、代码编译错误提示合集_第2张图片

无法rosdep init

出现以下错误

ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.

方法一

这是因为终端网络登陆不上这个地址,需要配置终端可以上WW
可以参考本博主的历史博客,关于如何给终端配置代理https://blog.csdn.net/weixin_43205582/article/details/103550956
注意在执行指令前要加上代理关键字

sudo proxychains rosdep init
sudo proxychains rosdep update

方法二

可以在可以上WW的浏览器打开网址
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
把里面的内容复制下来
环境搭建、代码编译错误提示合集_第3张图片

在本地新建对应目录/etc/ros/rosdep/sources.list.d

sudo mkdir -p /etc/ros/rosdep/sources.list.d

并定位到该目录:

cd /etc/ros/rosdep/sources.list.d

新建文件20-default.list:

sudo gedit 20-default.list

将上面打开网页中的内容复制粘贴到新建打开的文档中:

# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

并将所有raw.githubusercontent.com改为raw.github.com,得到如下最终文档(也可以暂时跳过这一步,实在不行再执行这一步):

# os-specific listings first
yaml https://raw.github.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

# generic
yaml https://raw.github.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.github.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.github.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://raw.github.com/ros/rosdistro/master/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

保存,关闭文件。
在终端运行:

sudo rosdep update
//或者终端可以上WW的情况下
sudo proxychains rosdep update

得到以下信息为成功
环境搭建、代码编译错误提示合集_第4张图片等于人为的将文件放置到本地对应位置,这一系列过程替代sudo rosdep init

其他方法请参考
https://blog.csdn.net/u013468614/article/details/102917569

编译出错

PluginlibFactory: The plugin for class ‘grid_map_rviz_plugin/GridMap‘ failed to load

解决方案

It's not finding the package grid_map_rviz_plugin. Is the package in the catkin_ws, compiled and devel/setup.bash sourced? I.e. cd ~/catkin_ws && catkin build grid_map_rviz_plugin && source devel/setup.bash && roslaunch aerial_mapper_demos 0-synthetic-cadastre-dsm.launch

参考以上回答,需要安装所需插件

sudo apt-get install libcanberra-gtk-module

并且在工作空间中运行

catkin build grid_map_rviz_plugin && source devel/setup.bash

编译过程中出现找不到.cmake文件的错误

这一般在终端中提示的是CMakeLists文件找不到某一依赖的.cmake文件
并且都会提供系统的搜索路径,你可以进入该目录下使用 find 指令进行对提示缺失的.cmake文件进行查找,一般情况下是找不到的
第一种可能
或许是该依赖包或者库安装的路径和编译的工程给出的路径是不一样的,实际上你是存在这个依赖或者库的,那么可以在根目录下搜素该.cmake文件,如果找到,那么在CMakeLists文件中直接用绝对路径添加该依赖或者库的查找路径
如当找torch的时候,CMakeLists添加

set(TORCH_PATH ~/.local/lib/python2.7/site-packages/torch/share/cmake/Torch) 
if( TORCH_PATH ) 
   message("TORCH_PATH set to: ${TORCH_PATH}")
  set(Torch_DIR ${TORCH_PATH})
else()
   message(FATAL_ERROR "Need to specify Torch path, e.g., pytorch/torch/share/cmake/Torch ")
endif()

find_package(Torch REQUIRED)

最终由Torch_DIR传递这个路径,让find_package命令进行查找

第二种可能
真的缺少这个依赖,那么可以考虑单独进行这个依赖的安装,搜索隐形去搜索缺失的对应依赖进行安装
如果是库的缺失需要进行对库的安装如Pytorch或者Eigen3

你可能感兴趣的:(TX2环境搭建,环境搭建)