Ubuntu22.04中ROS2-humble的CMake与anaconda库冲突

发布于:2024-12-06 ⋅ 阅读:(35) ⋅ 点赞:(0)

在创建ros2 humble中创建msg并用colcon build编译过程中出现以下警告:

(yolov) sss@sss:~/cnn/ros/ws$ colcon build
Starting >>> interfacedxp
Starting >>> testdxp
Finished <<< testdxp [0.62s]                                                  
--- stderr: interfacedxp                             
CMake Warning at /opt/ros/humble/share/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake:166 (add_library):
  Cannot generate a safe runtime search path for target
  interfacedxp__rosidl_generator_py because files in some directories may
  conflict with libraries in implicit directories:

    runtime library [libpython3.10.so.1.0] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/sss/anaconda3/envs/yolov/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
  /opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:286 (ament_execute_extensions)
  CMakeLists.txt:14 (rosidl_generate_interfaces)


CMake Warning at /opt/ros/humble/share/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake:226 (add_library):
  Cannot generate a safe runtime search path for target
  interfacedxp__rosidl_typesupport_fastrtps_c__pyext because files in some
  directories may conflict with libraries in implicit directories:

    runtime library [libpython3.10.so.1.0] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/sss/anaconda3/envs/yolov/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
  /opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:286 (ament_execute_extensions)
  CMakeLists.txt:14 (rosidl_generate_interfaces)


CMake Warning at /opt/ros/humble/share/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake:226 (add_library):
  Cannot generate a safe runtime search path for target
  interfacedxp__rosidl_typesupport_introspection_c__pyext because files in
  some directories may conflict with libraries in implicit directories:

    runtime library [libpython3.10.so.1.0] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/sss/anaconda3/envs/yolov/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
  /opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:286 (ament_execute_extensions)
  CMakeLists.txt:14 (rosidl_generate_interfaces)


CMake Warning at /opt/ros/humble/share/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake:226 (add_library):
  Cannot generate a safe runtime search path for target
  interfacedxp__rosidl_typesupport_c__pyext because files in some directories
  may conflict with libraries in implicit directories:

    runtime library [libpython3.10.so.1.0] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/sss/anaconda3/envs/yolov/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  /opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)
  /opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:286 (ament_execute_extensions)
  CMakeLists.txt:14 (rosidl_generate_interfaces)


---
Finished <<< interfacedxp [2.22s]

Summary: 2 packages finished [2.28s]
  1 package had stderr output: interfacedxp

借鉴了以下解决方案,但有人在评论区说没有解决问题​​​​​​,其实还剩一点没弄完,就是把原有export注释掉​

直接贴出我系统里面conda与ros2全部的.bashrc文件内容

# >>> fishros initialize >>>
source /opt/ros/humble/setup.bash
# <<< fishros initialize <<<

# >>> conda initialize >>>
__origin_path=$PATH #添加此行
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/sss/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/sss/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/sss/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/sss/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
export  PATH="$__origin_path:/home/sss/anaconda3/bin:/home/sss/anaconda3/bin" #添加此行
#export  PATH=$PATH:/home/sss/anaconda3/bin  #把这里注释掉
conda activate yolov

# <<< conda initialize <<<


export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/extras/CPUTI/lib64
export CUDA_HOME=/usr/local/cuda/bin
export PATH=$PATH:$LD_LIBRARY_PATH:$CUDA_HOME

source /home/sss/cnn/ros/ws/install/setup.bash