ln命令之make: *** 没有规则可以创建“/usr/lib/x86_64-linux-gnu/XXXXXX.so”需要的目标“XXX”暴力解法

当在Linux环境中遇到编译错误‘make: *** 没有规则可以创建“/usr/lib/x86_64-linux-gnu/XXXXXX.so”需要的目标’时,通常是由于缺少或链接断开的共享库导致。解决方法包括使用`locate`命令找到.so文件,然后使用带 `-s`, `-f`, `-i` 参数的`ln`命令创建软链接。如果`locate`找不到源文件,需检查库是否已安装或版本对应。确保正确处理后,即可正常编译项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.问题背景

在我们对项目进行编译时,可能会遇到make: *** 没有规则可以创建“/usr/lib/x86_64-linux-gnu/XXXXXX.so”需要的目标,这个问题,导致这个问题的原因大多来源于我们对某个项目的某个依赖库(卸载后)重新进行了源码编译,一般导致两种情况:

    1. 在原本的共享链接库路径下找不到原本的链接库文件.so
    1. 该文件断开链接

2.解决问题

我们进入到目标共享链接库目录下(当前为/usr/lib/x86_64-linux-gnu/),通过ls命令查看:
如图,一种情况为该目录下不存在所需的“xxx.so”文件,另一种情况即该文件存在,但显示为红色,如图中“libopencv_aruco.so”文件,红色即显示该链接为断开状态
在这里插入图片描述

解决步骤一:

通过locate命令查找该.so文件的存储位置

locate 'xxx.so'

如下图,当前寻找的.so文件为“libopencv_aruco.so”文件(即上图中红色链接库文件其一,链接为断开状态),可以看到该文件存在于/usr/local/lib中
在这里插入图片描述
!!:当locate在其他目录(一般为/usr/local/lib)找到.so文件后,不论是两种情况的哪一种(在报错目标目录不存在/存在但链接断开),均可通过一条shell命令进行解决(如上图)
即:

sudo ln -s -f -i /usr/local/lib/xxx.so /报错目录/xxx.so

语法为:

ls -s -f -i 源文件 目标文件

这也是标题的所说的“暴力”,即只要原始共享链接库文件存在,则不分错误情况,一步到位

关于ln命令,-s参数相信大家都比较熟知,即为目标文件创建软链接,而这里又加入的’-f’、’-i’参数才是暴力解决的关键:

-f:强制创建链接,即使目标文件已经存在
–i:交互模式,若目标文件已经存在,则提示用户确认进行覆盖

操作完成后,再次键入ls命令,可以看到该.so文件已经存在且正常,接下来,正常的去对项目进行编译即可。
在这里插入图片描述

解决步骤二:若通过locate命令查找不到源.so文件

1:查看该库是否已经安装/编译
2. 查看版本是否对应

对一第一种情况,如发现该库根本没有安装,找到指定版本安装就好了
对于第二种情况:
比如你的项目需要libopencv-core.so.3.2.0,但你的opencv是其实并不是3.2版本的,这样直接去源码编译opencv3.2就行了,编译过程中就会看到相对应的.so文件生成。

配置工作空间环境 Bash # 初始化工作空间(如果未完成) cd ~/primitive_ws catkin_init_workspace # 生成顶层CMakeLists.txt # 编译工作空间 catkin_make 运行catkin_make输出vae@vae-ASUS-TUF-Gaming-A15-FA507UU-FA507UU:~/primitive_ws$ catkin_make Base path: /home/vae/primitive_ws Source space: /home/vae/primitive_ws/src Build space: /home/vae/primitive_ws/build Devel space: /home/vae/primitive_ws/devel Install space: /home/vae/primitive_ws/install #### #### Running command: "cmake /home/vae/primitive_ws/src -DCATKIN_DEVEL_PREFIX=/home/vae/primitive_ws/devel -DCMAKE_INSTALL_PREFIX=/home/vae/primitive_ws/install -G Unix Makefiles" in "/home/vae/primitive_ws/build" #### -- Using CATKIN_DEVEL_PREFIX: /home/vae/primitive_ws/devel -- Using CMAKE_PREFIX_PATH: /opt/ros/noetic -- This workspace overlays: /opt/ros/noetic -- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") -- Using PYTHON_EXECUTABLE: /usr/bin/python3 -- Using Debian Python package layout -- Using empy: /usr/lib/python3/dist-packages/em.py -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/vae/primitive_ws/build/test_results -- Forcing gtest/gmock from source, though one was otherwise available. -- Found gtest sources under '/usr/src/googletest': gtests will be built -- Found gmock sources under '/usr/src/googletest': gmock will be built -- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") -- Using Python nosetests: /usr/bin/nosetests3 -- catkin 0.8.12 -- BUILD_SHARED_LIBS is on -- BUILD_SHARED_LIBS is on -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 19 packages in topological order: -- ~~ - quadrotor_msgs -- ~~ - map_generator -- ~~ - poscmd_2_odom -- ~~ - pose_utils -- ~~ - map_server -- ~~ - manual_take_over -- ~~ - odom_visualization -- ~~ - local_sensing_node -- ~~ - mockamap -- ~~ - so3_control -- ~~ - traj_utils -- ~~ - primitive_planner -- ~~ - swarm_bridge -- ~~ - uav_utils -- ~~ - assign_goals -- ~~ - random_goals -- ~~ - so3_quadrotor_simulator -- ~~ - rviz_plugins -- ~~ - selected_points_publisher -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +++ processing catkin package: 'quadrotor_msgs' -- ==> add_subdirectory(Primitive-Planner/src/Utils/quadrotor_msgs) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- quadrotor_msgs: 14 messages, 0 services -- +++ processing catkin package: 'map_generator' -- ==> add_subdirectory(Primitive-Planner/src/uav_simulator/map_generator) -- Eigen found (include: /usr/include/eigen3, version: 3.3.7) -- The imported target "vtkParseOGLExt" references the file "/usr/bin/vtkParseOGLExt-7.1" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "vtkRenderingPythonTkWidgets" references the file "/usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "vtk" references the file "/usr/bin/vtk" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "pvtk" references the file "/usr/bin/pvtk" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so) ** WARNING ** io features related to pcap will be disabled ** WARNING ** io features related to png will be disabled ** WARNING ** io features related to libusb-1.0 will be disabled -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so) -- QHULL found (include: /usr/include, lib: optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so) -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- looking for PCL_COMMON -- looking for PCL_KDTREE -- looking for PCL_OCTREE -- looking for PCL_SEARCH -- looking for PCL_SAMPLE_CONSENSUS -- looking for PCL_FILTERS -- looking for PCL_2D -- looking for PCL_GEOMETRY -- looking for PCL_IO -- looking for PCL_FEATURES -- looking for PCL_ML -- looking for PCL_SEGMENTATION -- looking for PCL_VISUALIZATION -- looking for PCL_SURFACE -- looking for PCL_REGISTRATION -- looking for PCL_KEYPOINTS -- looking for PCL_TRACKING -- looking for PCL_RECOGNITION -- looking for PCL_STEREO -- looking for PCL_APPS -- looking for PCL_IN_HAND_SCANNER -- looking for PCL_POINT_CLOUD_EDITOR -- looking for PCL_OUTOFCORE -- looking for PCL_PEOPLE -- Found PCL: pcl_common;pcl_kdtree;pcl_octree;pcl_search;pcl_sample_consensus;pcl_filters;pcl_io;pcl_features;pcl_ml;pcl_segmentation;pcl_visualization;pcl_surface;pcl_registration;pcl_keypoints;pcl_tracking;pcl_recognition;pcl_stereo;pcl_apps;pcl_outofcore;pcl_people;/usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;/usr/lib/x86_64-linux-gnu/libboost_date_time.so;/usr/lib/x86_64-linux-gnu/libboost_iostreams.so;/usr/lib/x86_64-linux-gnu/libboost_regex.so;optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so;/usr/lib/libOpenNI.so;/usr/lib/libOpenNI2.so;vtkChartsCore;vtkCommonColor;vtkCommonCore;vtksys;vtkCommonDataModel;vtkCommonMath;vtkCommonMisc;vtkCommonSystem;vtkCommonTransforms;vtkCommonExecutionModel;vtkFiltersGeneral;vtkCommonComputationalGeometry;vtkFiltersCore;vtkInfovisCore;vtkFiltersExtraction;vtkFiltersStatistics;vtkImagingFourier;vtkImagingCore;vtkalglib;vtkRenderingContext2D;vtkRenderingCore;vtkFiltersGeometry;vtkFiltersSources;vtkRenderingFreeType;/usr/lib/x86_64-linux-gnu/libfreetype.so;/usr/lib/x86_64-linux-gnu/libz.so;vtkFiltersModeling;vtkImagingSources;vtkInteractionStyle;vtkInteractionWidgets;vtkFiltersHybrid;vtkImagingColor;vtkImagingGeneral;vtkImagingHybrid;vtkIOImage;vtkDICOMParser;vtkmetaio;/usr/lib/x86_64-linux-gnu/libjpeg.so;/usr/lib/x86_64-linux-gnu/libpng.so;/usr/lib/x86_64-linux-gnu/libtiff.so;vtkRenderingAnnotation;vtkRenderingVolume;vtkIOXML;vtkIOCore;vtkIOXMLParser;/usr/lib/x86_64-linux-gnu/libexpat.so;vtkIOGeometry;vtkIOLegacy;vtkIOPLY;vtkRenderingLOD;vtkViewsContext2D;vtkViewsCore;vtkRenderingContextOpenGL2;vtkRenderingOpenGL2;FLANN::FLANN -- +++ processing catkin package: 'poscmd_2_odom' -- ==> add_subdirectory(Primitive-Planner/src/uav_simulator/fake_drone) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- +++ processing catkin package: 'pose_utils' -- ==> add_subdirectory(Primitive-Planner/src/Utils/pose_utils) -- +++ processing catkin package: 'map_server' -- ==> add_subdirectory(map_server) CMake Error at /opt/ros/noetic/share/catkin/cmake/catkin_workspace.cmake:121 (add_subdirectory): The source directory /home/vae/primitive_ws/src/map_server does not contain a CMakeLists.txt file. Call Stack (most recent call first): CMakeLists.txt:69 (catkin_workspace) -- +++ processing catkin package: 'manual_take_over' -- ==> add_subdirectory(Primitive-Planner/src/Utils/manual_take_over) -- +++ processing catkin package: 'odom_visualization' -- ==> add_subdirectory(Primitive-Planner/src/Utils/odom_visualization) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- +++ processing catkin package: 'local_sensing_node' -- ==> add_subdirectory(Primitive-Planner/src/uav_simulator/local_sensing) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy CMake Warning at /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:166 (message): catkin_package() DEPENDS on 'Eigen' but neither 'Eigen_INCLUDE_DIRS' nor 'Eigen_LIBRARIES' is defined. Call Stack (most recent call first): /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:102 (_catkin_package) Primitive-Planner/src/uav_simulator/local_sensing/CMakeLists.txt:72 (catkin_package) -- +++ processing catkin package: 'mockamap' -- ==> add_subdirectory(Primitive-Planner/src/uav_simulator/mockamap) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- +++ processing catkin package: 'so3_control' -- ==> add_subdirectory(Primitive-Planner/src/uav_simulator/so3_control) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- +++ processing catkin package: 'traj_utils' -- ==> add_subdirectory(Primitive-Planner/src/planner/traj_utils) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- traj_utils: 2 messages, 0 services -- +++ processing catkin package: 'primitive_planner' -- ==> add_subdirectory(Primitive-Planner/src/planner/plan_manage) -- Eigen found (include: /usr/include/eigen3, version: 3.3.7) -- The imported target "vtkParseOGLExt" references the file "/usr/bin/vtkParseOGLExt-7.1" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "vtkRenderingPythonTkWidgets" references the file "/usr/lib/x86_64-linux-gnu/libvtkRenderingPythonTkWidgets.so" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "vtk" references the file "/usr/bin/vtk" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- The imported target "pvtk" references the file "/usr/bin/pvtk" but this file does not exist. Possible reasons include: * The file was deleted, renamed, or moved to another location. * An install or uninstall procedure did not complete successfully. * The installation package was faulty and contained "/usr/lib/cmake/vtk-7.1/VTKTargets.cmake" but not all the files it references. -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so) ** WARNING ** io features related to pcap will be disabled ** WARNING ** io features related to png will be disabled ** WARNING ** io features related to libusb-1.0 will be disabled -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- OpenNI2 found (include: /usr/include/openni2, lib: /usr/lib/libOpenNI2.so) -- QHULL found (include: /usr/include, lib: optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so) -- OpenNI found (include: /usr/include/ni, lib: /usr/lib/libOpenNI.so) -- looking for PCL_COMMON -- looking for PCL_KDTREE -- looking for PCL_OCTREE -- looking for PCL_SEARCH -- looking for PCL_SAMPLE_CONSENSUS -- looking for PCL_FILTERS -- looking for PCL_2D -- looking for PCL_GEOMETRY -- looking for PCL_IO -- looking for PCL_FEATURES -- looking for PCL_ML -- looking for PCL_SEGMENTATION -- looking for PCL_VISUALIZATION -- looking for PCL_SURFACE -- looking for PCL_REGISTRATION -- looking for PCL_KEYPOINTS -- looking for PCL_TRACKING -- looking for PCL_RECOGNITION -- looking for PCL_STEREO -- looking for PCL_APPS -- looking for PCL_IN_HAND_SCANNER -- looking for PCL_POINT_CLOUD_EDITOR -- looking for PCL_OUTOFCORE -- looking for PCL_PEOPLE -- Found PCL: pcl_common;pcl_kdtree;pcl_octree;pcl_search;pcl_sample_consensus;pcl_filters;pcl_io;pcl_features;pcl_ml;pcl_segmentation;pcl_visualization;pcl_surface;pcl_registration;pcl_keypoints;pcl_tracking;pcl_recognition;pcl_stereo;pcl_apps;pcl_outofcore;pcl_people;/usr/lib/x86_64-linux-gnu/libboost_system.so;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;/usr/lib/x86_64-linux-gnu/libboost_date_time.so;/usr/lib/x86_64-linux-gnu/libboost_iostreams.so;/usr/lib/x86_64-linux-gnu/libboost_regex.so;optimized;/usr/lib/x86_64-linux-gnu/libqhull.so;debug;/usr/lib/x86_64-linux-gnu/libqhull.so;/usr/lib/libOpenNI.so;/usr/lib/libOpenNI2.so;vtkChartsCore;vtkCommonColor;vtkCommonCore;vtksys;vtkCommonDataModel;vtkCommonMath;vtkCommonMisc;vtkCommonSystem;vtkCommonTransforms;vtkCommonExecutionModel;vtkFiltersGeneral;vtkCommonComputationalGeometry;vtkFiltersCore;vtkInfovisCore;vtkFiltersExtraction;vtkFiltersStatistics;vtkImagingFourier;vtkImagingCore;vtkalglib;vtkRenderingContext2D;vtkRenderingCore;vtkFiltersGeometry;vtkFiltersSources;vtkRenderingFreeType;/usr/lib/x86_64-linux-gnu/libfreetype.so;/usr/lib/x86_64-linux-gnu/libz.so;vtkFiltersModeling;vtkImagingSources;vtkInteractionStyle;vtkInteractionWidgets;vtkFiltersHybrid;vtkImagingColor;vtkImagingGeneral;vtkImagingHybrid;vtkIOImage;vtkDICOMParser;vtkmetaio;/usr/lib/x86_64-linux-gnu/libjpeg.so;/usr/lib/x86_64-linux-gnu/libpng.so;/usr/lib/x86_64-linux-gnu/libtiff.so;vtkRenderingAnnotation;vtkRenderingVolume;vtkIOXML;vtkIOCore;vtkIOXMLParser;/usr/lib/x86_64-linux-gnu/libexpat.so;vtkIOGeometry;vtkIOLegacy;vtkIOPLY;vtkRenderingLOD;vtkViewsContext2D;vtkViewsCore;vtkRenderingContextOpenGL2;vtkRenderingOpenGL2;FLANN::FLANN (Required is at least version "1.7") -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- +++ processing catkin package: 'swarm_bridge' -- ==> add_subdirectory(Primitive-Planner/src/planner/swarm_bridge) -- +++ processing catkin package: 'uav_utils' -- ==> add_subdirectory(Primitive-Planner/src/Utils/uav_utils) -- +++ processing catkin package: 'assign_goals' -- ==> add_subdirectory(Primitive-Planner/src/Utils/assign_goals) -- +++ processing catkin package: 'random_goals' -- ==> add_subdirectory(Primitive-Planner/src/Utils/random_goals) -- +++ processing catkin package: 'so3_quadrotor_simulator' -- ==> add_subdirectory(Primitive-Planner/src/uav_simulator/so3_quadrotor_simulator) CMake Warning at /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:166 (message): catkin_package() DEPENDS on 'Eigen3' but neither 'Eigen3_INCLUDE_DIRS' nor 'Eigen3_LIBRARIES' is defined. Call Stack (most recent call first): /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:102 (_catkin_package) Primitive-Planner/src/uav_simulator/so3_quadrotor_simulator/CMakeLists.txt:29 (catkin_package) CMake Warning at /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:166 (message): catkin_package() DEPENDS on 'system_lib' but neither 'system_lib_INCLUDE_DIRS' nor 'system_lib_LIBRARIES' is defined. Call Stack (most recent call first): /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:102 (_catkin_package) Primitive-Planner/src/uav_simulator/so3_quadrotor_simulator/CMakeLists.txt:29 (catkin_package) -- +++ processing catkin package: 'rviz_plugins' -- ==> add_subdirectory(Primitive-Planner/src/Utils/rviz_plugins) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy CMake Warning at /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:166 (message): catkin_package() DEPENDS on 'system_lib' but neither 'system_lib_INCLUDE_DIRS' nor 'system_lib_LIBRARIES' is defined. Call Stack (most recent call first): /opt/ros/noetic/share/catkin/cmake/catkin_package.cmake:102 (_catkin_package) Primitive-Planner/src/Utils/rviz_plugins/CMakeLists.txt:12 (catkin_package) -- Using Qt5 based on the rviz_QT_VERSION: 5.12.8 -- +++ processing catkin package: 'selected_points_publisher' -- ==> add_subdirectory(Primitive-Planner/src/Utils/selected_points_publisher) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy -- Configuring incomplete, errors occurred! See also "/home/vae/primitive_ws/build/CMakeFiles/CMakeOutput.log". See also "/home/vae/primitive_ws/build/CMakeFiles/CMakeError.log". Invoking "cmake" failed
最新发布
07-18
<think>我们正在处理一个ROS Noetic工作空间编译问题。用户之前尝试在`primitive_ws`工作空间中为`map_server`创建符号链接,但在编译过程中遇到了CMake错误,错误信息提示`map_server`的`CMakeLists.txt`文件缺失。 根据用户提供的上下文,错误可能发生在执行`catkin_make`时,因为`map_server`包是通过符号链接添加到工作空间`src`目录的。而符号链接指向的是系统安装的`map_server`包(路径为`/opt/ros/noetic/share/map_server`)。但是,在ROS中,`share`目录下的包通常只包含运行时的文件(如launch、config等),而不包含构建所需的`CMakeLists.txt`和`package.xml`文件。这些构建文件通常位于`src`目录下的包中。 因此,问题在于:通过符号链接将`/opt/ros/noetic/share/map_server`链接到工作空间的`src`目录,会导致`catkin_make`尝试构建这个包,但该目录下没有`CMakeLists.txt`文件(因为系统安装的包已经编译过了,所以`share`目录下只有运行时的资源)。 ### 正确的方法 在ROS中,如果你想要覆盖一个系统包(例如`map_server`)或者修改它,你应该获取该包的源代码,并将其放入你的工作空间`src`目录中(而不是使用符号链接到`share`目录)。对于`map_server`包,源代码位于`map_server`的源码包中,它通常包含`CMakeLists.txt`。 ### 解决步骤 1. **移除之前创建的符号链接**: ```bash cd ~/primitive_ws/src rm map_server ``` 2. **获取`map_server`的源代码**: ```bash # 使用apt-get source获取源代码(需要先启用源码仓库) sudo sh -c 'echo "deb-src http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' sudo apt update sudo apt-get install dpkg-dev # 确保有dpkg-dev工具 mkdir -p ~/primitive_ws/src cd ~/primitive_ws/src apt-get source ros-noetic-map-server ``` 或者,你可以从ROS的GitHub仓库克隆: ```bash cd ~/primitive_ws/src git clone -b noetic-devel https://github.com/ros-planning/navigation.git ``` 注意:`map_server`包在`navigation`仓库中,所以克隆整个仓库后,你会在`navigation/map_server`目录下找到它。 3. **重新编译工作空间**: ```bash cd ~/primitive_ws catkin_make ``` 4. **更新环境**: ```bash source devel/setup.bash ``` 5. **验证**: ```bash rospack find map_server # 应该输出:/home/vae/primitive_ws/src/navigation/map_server ``` ### 如果不需要修改`map_server`,只需要使用系统包 如果你不需要修改`map_server`,那么不需要将它放入工作空间。直接使用系统安装的包即可。在编译你的工作空间时,`map_server`作为依赖会被系统路径找到。 ### 关于用户之前出现的错误 用户之前可能遇到类似引用[1]中的错误(多个同名包),这是因为在创建符号链接到`/opt/ros/noetic/share/map_server`后,工作空间中存在一个`map_server`包,同时系统路径下也有一个,导致冲突。因此,移除符号链接并正确获取源代码(或完全不放入工作空间)可以避免此问题。 ### 引用说明 - 引用[1]提到`Multiple packages found with the same name`,这通常是由于同一个包在多个位置被找到(比如工作空间和系统路径都有)[^1]。 - 引用[2][3][4]虽然提供了其他编译错误的解决方法,但与本问题关联不大。 ### 总结 - 不要将系统`share`目录下的包通过符号链接放入工作空间`src`目录,因为缺少构建文件。 - 如果需要覆盖系统包,应该获取该包的源代码并放入工作空间`src`目录。 - 如果不需要修改,则无需放入工作空间,直接使用系统包。 按照上述步骤操作,应该能解决`CMakeLists.txt`缺失导致的编译错误。 §§相关问题§§ 1. 如何正确覆盖ROS系统包? 2. 如何获取ROS包的源代码? 3. 为什么ROS工作空间中的符号链接会导致编译错误?</think>### 解决 ROS Noetic 中 map_server 编译错误的完整指南 您在尝试编译 ROS 工作空间时遇到的 `CMakeError: map_server CMakeLists.txt missing` 错误,通常是由于以下原因造成的: #### 🛠 错误原因分析 1. **符号链接指向错误位置** `map_server` 的构建文件(CMakeLists.txt)位于源码目录,而非安装目录: ```bash # 错误链接(指向安装目录) ln -s /opt/ros/noetic/share/map_server src/map_server # 正确应指向源码目录(通常位于) /opt/ros/noetic/share/map_server/../src/map_server ``` 2. **工作空间覆盖冲突** 当工作空间中存在同名包时,ROS 会优先使用工作空间版本,但符号链接会导致系统包和工作空间包冲突[^1]。 3. **文件路径缺失** 错误信息明确提示 CMakeLists.txt 文件缺失,因为安装目录下只有运行时文件,没有构建文件。 #### ✅ 解决方案步骤 1. **移除错误符号链接** ```bash cd ~/primitive_ws/src rm -rf map_server # 删除无效符号链接 ``` 2. **获取正确源码** ```bash # 方法1:从官方仓库克隆 git clone -b noetic-devel https://github.com/ros-planning/navigation.git ln -s navigation/map_server . # 创建正确链接 # 方法2:安装源码包 sudo apt-get source ros-noetic-map-server cp -r ros-noetic-map-server-* src/map_server ``` 3. **验证文件存在性** ```bash ls src/map_server/CMakeLists.txt # 应显示文件路径 ``` 4. **重新编译工作空间** ```bash cd ~/primitive_ws catkin_make clean # 清理旧编译 catkin_make ``` 5. **环境变量配置** ```bash echo "source ~/primitive_ws/devel/setup.bash" >> ~/.bashrc source ~/.bashrc ``` #### ⚠️ 常见问题排查 1. **多个同名包错误** ```bash # 检查重复包 rospack list | grep map_server # 若存在重复,移除工作空间外的版本 sudo apt remove ros-noetic-map-server ``` 2. **Python脚本路径错误** ```text CMake Error: catkin_install_python() called with non-existing file ``` 解决方案: ```bash # 确保脚本路径正确 ls src/map_server/scripts/*.py # 在CMakeLists.txt中修正路径 catkin_install_python(PROGRAMS scripts/map_server.py DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}) ``` 3. **依赖缺失问题** ```bash # 安装所有依赖 rosdep install --from-paths src --ignore-src -y ``` #### 🌐 工作空间结构参考 正确的工作空间结构应包含完整源码: ``` primitive_ws/ ├── build/ ├── devel/ └── src/ ├── CMakeLists.txt (工作空间级) └── map_server/ (完整源码) ├── CMakeLists.txt (包级) ├── package.xml ├── include/ └── src/ ``` > 关键点:必须确保 `src/map_server` 目录包含完整的构建文件(CMakeLists.txt + 源码),而非仅运行时文件[^3]。
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

涛涛ALG

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值