鱼香ROS社区
    • 版块
    • 最新
    • 未解决
    • 已解决
    • 群组
    • 注册
    • 登录
    紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
    提问前必看的发帖注意事项: 社区问答规则(小鱼个人)更新 | 高质量帖子发布指南

    8.1.3 cmake找不到源文件

    已定时 已固定 已锁定 已移动
    动手学ROS2
    cmake报错 找不到源文件
    2
    3
    406
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • 4
      开心
      最后由 编辑

      空间构建报错:

      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
      
      ganyuanzhenG 1 条回复 最后回复 回复 引用 0
      • ganyuanzhenG
        Elysia 技术大佬 @43996173
        最后由 编辑

        @43996173 在 8.1.3 cmake找不到源文件 中说:

        spin_motion_cotroller.cpp

        文件名:spin_motion_cotroller.cpp
        
        CMake里的文件名:src/spin_motion_controller.cpp
        

        是你的CMake文件名错了

        我难道就没有一段英勇,美好而又虚幻的过去……幸运地写在金叶片上?

        4 1 条回复 最后回复 回复 引用 0
        • 4
          开心 @ganyuanzhen
          最后由 编辑

          @ganyuanzhen 在 8.1.3 cmake找不到源文件 中说:

          spin_motion_cotroller.cpp

          收到,谢谢

          1 条回复 最后回复 回复 引用 0
          • 第一个帖子
            最后一个帖子
          皖ICP备16016415号-7
          Powered by NodeBB | 鱼香ROS