ros的catkin_ws/src的CMakeList.txt原文件

修复ROS Catkin_ws CMakeLists.txt错误指南
本文提供了解决ROS环境下catkin_ws/src目录中CMakeLists.txt文件被误修改导致的问题方案。详细介绍了如何恢复原文件,避免出现如CMakeError等编译错误,对于不慎改动此关键配置文件的开发者尤其有用。

ros的catkin_ws/src的CMakeList.txt原文件

不知道有没有人跟我一样不小心把catkin_ws/src的CMakeLists.txt文件改掉导致出现以下错误的。

CMake Error: File /home/weiwie/catkin_ws/src/package.xml does not exist.
CMake Error at /opt/ros/kinetic/share/catkin/cmake/stamp.cmake:10 (configure_file):
....
....
....
CMake Error at /opt/ros/kinetic/share/catkin/cmake/catkin_package.cmake:116 (message):
catkin_package() 'catkin' must be listed as a buildtool dependency in the
  package.xml

因为网络上找不到这一个文件,所以我就自己又重新下载了一遍ros,并且把它备份下来,希望对那些不小心修改了该文件的人有所帮助。

下面便是ros的catkin_ws/src的CMakeList.txt文件原先的代码:

也是/opt/ros/kinetic/share/catkin/cmake/toplevel.cmake的代码

因为这两个的是动态链接来的,修改一个另一个也会被更改,而且如果你修改了你的那个主CMakeLists.txt文件的话,你的下一个工作空间也会一直用已经修改的那个文件的代码,导致无法挽回的错误。

# toplevel CMakeLists.txt for a catkin workspace
# catkin/cmake/toplevel.cmake

cmake_minimum_required(VERSION 2.8.3)

set(CATKIN_TOPLEVEL TRUE)

# search for catkin within the workspace
set(_cmd "catkin_find_pkg" "catkin" "${CMAKE_SOURCE_DIR}")
execute_process(COMMAND ${_cmd}
  RESULT_VARIABLE _res
  OUTPUT_VARIABLE _out
  ERROR_VARIABLE _err
  OUTPUT_STRIP_TRAILING_WHITESPACE
  ERROR_STRIP_TRAILING_WHITESPACE
)
if(NOT _res EQUAL 0 AND NOT _res EQUAL 2)
  # searching fot catkin resulted in an error
  string(REPLACE ";" " " _cmd_str "${_cmd}")
  message(FATAL_ERROR "Search for 'catkin' in workspace failed (${_cmd_str}): ${_err}")
endif()

# include catkin from workspace or via find_package()
if(_res EQUAL 0)
  set(catkin_EXTRAS_DIR "${CMAKE_SOURCE_DIR}/${_out}/cmake")
  # include all.cmake without add_subdirectory to let it operate in same scope
  include(${catkin_EXTRAS_DIR}/all.cmake NO_POLICY_SCOPE)
  add_subdirectory("${_out}")

else()
  # use either CMAKE_PREFIX_PATH explicitly passed to CMake as a command line argument
  # or CMAKE_PREFIX_PATH from the environment
  if(NOT DEFINED CMAKE_PREFIX_PATH)
    if(NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")
      string(REPLACE ":" ";" CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH})
    endif()
  endif()

  # list of catkin workspaces
  set(catkin_search_path "")
  foreach(path ${CMAKE_PREFIX_PATH})
    if(EXISTS "${path}/.catkin")
      list(FIND catkin_search_path ${path} _index)
      if(_index EQUAL -1)
        list(APPEND catkin_search_path ${path})
      endif()
    endif()
  endforeach()

  # search for catkin in all workspaces
  set(CATKIN_TOPLEVEL_FIND_PACKAGE TRUE)
  find_package(catkin QUIET
    NO_POLICY_SCOPE
    PATHS ${catkin_search_path}
    NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
  unset(CATKIN_TOPLEVEL_FIND_PACKAGE)

  if(NOT catkin_FOUND)
    message(FATAL_ERROR "find_package(catkin) failed. catkin was neither found in the workspace nor in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was sourced before.")
  endif()
endif()

catkin_workspace()
chen@chen-VirtualBox:~/catkin_ws$ catkin_make 不到命令 “catkin_make”,但可以通过以下软件包安装它: sudo apt install catkin chen@chen-VirtualBox:~/catkin_ws$ catkin_make Base path: /home/chen/catkin_ws Source space: /home/chen/catkin_ws/src Build space: /home/chen/catkin_ws/build Devel space: /home/chen/catkin_ws/devel Install space: /home/chen/catkin_ws/install Creating symlink "/home/chen/catkin_ws/src/CMakeLists.txt" pointing to "/usr/share/catkin/cmake/toplevel.cmake" #### #### Running command: "cmake /home/chen/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/chen/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/chen/catkin_ws/install -G Unix Makefiles" in "/home/chen/catkin_ws/build" #### -- The C compiler identification is GNU 11.4.0 -- The CXX compiler identification is GNU 11.4.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Using CATKIN_DEVEL_PREFIX: /home/chen/catkin_ws/devel -- Using CMAKE_PREFIX_PATH: -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.10.12", minimum required is "3") -- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Using empy: /usr/bin/empy -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/chen/catkin_ws/build/test_results -- GTest is available -- GMock is not available. Please install libgmock-dev to enable tests involving GMock. -- nosetests not found, Python tests can not be run (try installing package 'python3-nose') -- Found Threads: TRUE -- catkin 0.8.10 -- BUILD_SHARED_LIBS is on Traceback (most recent call last): File "/home/chen/catkin_ws/build/catkin_generated/generate_cached_setup.py", line 22, in <module> code = generate_environment_script('/home/chen/catkin_ws/devel/env.sh') File "/usr/lib/python3/dist-packages/catkin/environment_cache.py", line 63, in generate_environment_script env_after = ast.literal_eval(output.decode('utf8')) File "/usr/lib/python3.10/ast.py", line 64, in literal_eval node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval') File "/usr/lib/python3.10/ast.py", line 50, in parse return compile(source, filename, mode, flags, File "<unknown>", line 1 ROS_DISTRO was set to 'humble' before. Please make sure that the environment does not mix paths from different distributions. ^^^ SyntaxError: invalid syntax CMake Error at /usr/share/catkin/cmake/safe_execute_process.cmake:11 (message): execute_process(/usr/bin/python3 "/home/chen/catkin_ws/build/catkin_generated/generate_cached_setup.py") returned error code 1 Call Stack (most recent call first): /usr/share/catkin/cmake/all.cmake:221 (safe_execute_process) /usr/share/catkin/cmake/catkinConfig.cmake:20 (include) CMakeLists.txt:58 (find_package) -- Configuring incomplete, errors occurred! See also "/home/chen/catkin_ws/build/CMakeFiles/CMakeOutput.log". Invoking "cmake" failed
最新发布
09-06
评论 20
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值