紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
8.1.3 cmake找不到源文件
-
空间构建报错:
tingbo@DESKTOP-NHH5E05:~/chapt8/learn_pluginlib$ colcon build Starting >>> motion_control_system --- stderr: motion_control_system CMake Error at CMakeLists.txt:13 (add_library): Cannot find source file: src/spin_motion_controller.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc CMake Error at CMakeLists.txt:13 (add_library): No SOURCES given to target: spin_motion_controller CMake Generate step failed. Build files cannot be regenerated correctly. --- Failed <<< motion_control_system [1.50s, exited with code 1] Summary: 0 packages finished [1.73s] 1 package failed: motion_control_system 1 package had stderr output: motion_control_system tingbo@DESKTOP-NHH5E05:~/chapt8/learn_pluginlib$ colcon build Starting >>> motion_control_system --- stderr: motion_control_system CMake Error at CMakeLists.txt:13 (add_library): Cannot find source file: src/spin_motion_controller.cpp Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc CMake Error at CMakeLists.txt:13 (add_library): No SOURCES given to target: spin_motion_controller CMake Generate step failed. Build files cannot be regenerated correctly. --- Failed <<< motion_control_system [1.51s, exited with code 1] Summary: 0 packages finished [1.76s] 1 package failed: motion_control_system 1 package had stderr output: motion_control_system
cmakelists.txt代码:
cmake_minimum_required(VERSION 3.8) project(motion_control_system) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() #==========查找依赖========= # find dependencies find_package(ament_cmake REQUIRED) find_package(pluginlib REQUIRED) include_directories(include ) #===========添加库文件========\ add_library(spin_motion_controller SHARED src/spin_motion_controller.cpp) ament_target_dependencies(spin_motion_controller pluginlib) install(TARGETS spin_motion_controller ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin ) install(DIRECTORY include/ DESTINATION include/ ) #导出插件描述文件 pluginlib_export_plugin_description_file(motion_control_system spin_motion_plugins.xml) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights # comment the line when a copyright and license is added to all source files set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() ament_package()
spin_motion_cotroller.cpp代码:
#include <iostream> #include "motion_control_system/spin_motion_controller.hpp" namespace motion_control_system{ void SpinMotionController::start() { //实现旋转逻辑运动控制逻辑 std::cout<<"SpinMotionController::start"<<std::endl; } void SpinMotionController::stop() { // 停止运动控制 std::cout<<"SpinMotionController::stop"<<std::endl; } } //namespace motion_control_system #include "pluginlib/class_list_macros.hpp" PLUGINLIB_EXPORT_CLASS(motion_control_system::SpinMotionController, motion_control_system::MotionController)
spin_motion_controller.hpp代码:
#ifndef SPIN_MOTION_CONTROLLER_HPP #define SPIN_MOTION_CONTROLLER_HPP #include "motion_control_system/motion_control_interface.hpp" namespace motion_control_system { class SpinMotionController : public MotionController { public: void start() override; void stop() override; }; } // namespace motion_control_system #endif // SPIN_MOTION_CONTROLLER_HPP
-
@43996173 在 8.1.3 cmake找不到源文件 中说:
spin_motion_cotroller.cpp
文件名:spin_motion_cotroller.cpp CMake里的文件名:src/spin_motion_controller.cpp
是你的CMake文件名错了
-