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

    重新运行代码时出现:UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces'

    已定时 已固定 已锁定 已移动 已解决
    ROS 2相关问题
    ros2 humble 错误
    2
    11
    2.0k
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • A
      曼森的林佳树甜甜甜 @andrew_liumuran
      最后由 编辑

      @andrew_liumuran
      类似的问题 链接文本

      1 条回复 最后回复 回复 引用 0
      • 小鱼小
        小鱼 技术大佬 @andrew_liumuran
        最后由 编辑

        @andrew_liumuran 贴一下CmakeKList.txt 问题应该是没添加依赖造成的

        BUG表现如下
        自定义消息,编译不报错,运行就出错
        Traceback (most recent call last):
        File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support
        return importlib.import_module(module_name, package=pkg_name)
        File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
        File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
        File "<frozen importlib._bootstrap>", line 991, in _find_and_load
        File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
        File "<frozen importlib._bootstrap>", line 556, in module_from_spec
        File "<frozen importlib._bootstrap_external>", line 1166, in create_module
        File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
        ImportError: /home/ros2/code/town_ws/install/village_interfaces/lib/libvillage_interfaces__rosidl_generator_c.so: undefined symbol: sensor_msgs__msg__Image__init

        During handling of the above exception, another exception occurred:

        Traceback (most recent call last):
        File "/home/ros2/code/town_ws/install/village_li/lib/village_li/li4_node", line 11, in <module>
        load_entry_point('village-li==0.0.0', 'console_scripts', 'li4_node')()
        File "/home/ros2/code/town_ws/install/village_li/lib/python3.8/site-packages/village_li/li4.py", line 46, in main
        node = Li4Node() # 新建一个节点
        File "/home/ros2/code/town_ws/install/village_li/lib/python3.8/site-packages/village_li/li4.py", line 23, in init
        self.borrow_server = self.create_service(BorrowMoney,"borrow_money",self.borrow_money_callback)
        File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 1295, in create_service
        check_for_type_support(srv_type)
        File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 29, in check_for_type_support
        msg_type.class.import_type_support()
        File "/home/ros2/code/town_ws/install/village_interfaces/lib/python3.8/site-packages/village_interfaces/srv/_borrow_money.py", line 316, in import_type_support
        module = import_type_support('village_interfaces')
        File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support
        raise UnsupportedTypeSupport(pkg_name)
        rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces'

        原因:
        自定义消息未添加对其他消息的依赖

        解决办法,添加依赖在CMakeists.txt中
        find_package(rosidl_default_generators REQUIRED)
        rosidl_generate_interfaces(${PROJECT_NAME}
        #---msg---
        "msg/Novel.msg"
        #---srv---
        "srv/BorrowMoney.srv"
        "srv/SellNovel.srv"
        DEPENDENCIES std_msgs sensor_msgs
        )
        ————————————————
        版权声明:本文为CSDN博主「鱼香ROS」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
        原文链接:https://blog.csdn.net/qq_27865227/article/details/119651587

        新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

        A 1 条回复 最后回复 回复 引用 0
        • 小鱼小 小鱼 将这个主题标记为已解决,在
        • A
          曼森的林佳树甜甜甜 @小鱼
          最后由 编辑

          @小鱼
          小鱼您好,这是CmakeKList.txt,修改编译运行后仍有相同错误,还得麻烦您,谢谢!

          # /home/andrew/town_ws/src/village_interfaces/CMakeLists.txt
          cmake_minimum_required(VERSION 3.8)
          project(village_interfaces)
          
          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)
          # uncomment the following section in order to fill in
          # further dependencies manually.
          # find_package(<dependency> REQUIRED)
          
          if(BUILD_TESTING)
            find_package(ament_lint_auto REQUIRED)
            #添加对sensor_msgs的
            find_package(sensor_msgs REQUIRED)
            find_package(rosidl_default_generators 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()
          #添加消息文件和依赖
          rosidl_generate_interfaces(${PROJECT_NAME}
            "msg/Novel.msg"
            "srv/BorrowMoney.srv"
            "srv/SellNovel.srv"
             DEPENDENCIES std_msgs sensor_msgs 
           )
          ament_package()
          
          小鱼小 1 条回复 最后回复 回复 引用 0
          • 小鱼小
            小鱼 技术大佬 @andrew_liumuran
            最后由 编辑

            @andrew_liumuran 在 重新运行代码时出现:UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces' 中说:

            #添加对sensor_msgs的
            find_package(sensor_msgs REQUIRED)

            把这个移到

            @andrew_liumuran 在 重新运行代码时出现:UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces' 中说:

            if(BUILD_TESTING)

            之前

            新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

            A 1 条回复 最后回复 回复 引用 0
            • A
              曼森的林佳树甜甜甜 @小鱼
              最后由 编辑

              @小鱼

              小鱼您好,修改之后,还是相同的报错 😰 😰 谢谢您

              project(village_interfaces)
              
              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(sensor_msgs REQUIRED)
              find_package(std_msgs REQUIRED)
              find_package(rosidl_default_generators REQUIRED)
              
              # uncomment the following section in order to fill in
              # further dependencies manually.
              # find_package(<dependency> REQUIRED)
              
              if(BUILD_TESTING)
                find_package(ament_lint_auto REQUIRED)
                #添加对sensor_msgs的
                find_package(sensor_msgs REQUIRED)
                find_package(rosidl_default_generators 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()
              #添加消息文件和依赖
              rosidl_generate_interfaces(${PROJECT_NAME}
                "msg/Novel.msg"
                "srv/BorrowMoney.srv"
                "srv/SellNovel.srv"
                 DEPENDENCIES std_msgs sensor_msgs 
               )
              ament_package()
              

              以下是报错

              andrew@ros2:~/town_ws$ ros2 run village_li li3_node
              [INFO] [1674031680.523058434] [li3]: 大家好,我是李三,李四他哥,我可以白嫖李四的小说!
              Traceback (most recent call last):
                File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support
                  return importlib.import_module(module_name, package=pkg_name)
                File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
                  return _bootstrap._gcd_import(name[level:], package, level)
                File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
                File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
                File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
                File "<frozen importlib._bootstrap>", line 674, in _load_unlocked
                File "<frozen importlib._bootstrap>", line 571, in module_from_spec
                File "<frozen importlib._bootstrap_external>", line 1176, in create_module
                File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
              ImportError: /home/andrew/town_ws/install/village_interfaces/lib/libvillage_interfaces__rosidl_generator_c.so: ELF file's phentsize not the expected size
              
              During handling of the above exception, another exception occurred:
              
              Traceback (most recent call last):
                File "/home/andrew/town_ws/install/village_li/lib/village_li/li3_node", line 33, in <module>
                  sys.exit(load_entry_point('village-li==0.0.0', 'console_scripts', 'li3_node')())
                File "/home/andrew/town_ws/install/village_li/lib/python3.10/site-packages/village_li/li3.py", line 60, in main
                  node = Li3Node("li3")  # 新建一个节点
                File "/home/andrew/town_ws/install/village_li/lib/python3.10/site-packages/village_li/li3.py", line 18, in __init__
                  self.borrow_client =self.create_client(BorrowMoney,"borrow_money")
                File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/node.py", line 1413, in create_client
                  check_is_valid_srv_type(srv_type)
                File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/type_support.py", line 51, in check_is_valid_srv_type
                  check_for_type_support(srv_type)
                File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/type_support.py", line 29, in check_for_type_support
                  msg_or_srv_type.__class__.__import_type_support__()
                File "/home/andrew/town_ws/install/village_interfaces/local/lib/python3.10/dist-packages/village_interfaces/srv/_borrow_money.py", line 301, in __import_type_support__
                  module = import_type_support('village_interfaces')
                File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support
                  raise UnsupportedTypeSupport(pkg_name)
              rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces'
              [ros2run]: Process exited with failure 1
              
              小鱼小 1 条回复 最后回复 回复 引用 0
              • 小鱼小
                小鱼 技术大佬 @andrew_liumuran
                最后由 编辑

                @andrew_liumuran 把你的消息文件内容贴一下

                新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

                A 1 条回复 最后回复 回复 引用 0
                • A
                  曼森的林佳树甜甜甜 @小鱼
                  最后由 编辑

                  @小鱼 😊

                  /home/andrew/town_ws/src/village_interfaces/msg/Novel.msg

                  # 直接使用ROS2原始的数据类型
                  string content
                  # 图像消息,调用sensor_msgs下的Image类型
                  sensor_msgs/Image image
                  
                  
                  小鱼小 2 条回复 最后回复 回复 引用 0
                  • 小鱼小
                    小鱼 技术大佬 @andrew_liumuran
                    最后由 编辑

                    @andrew_liumuran 看起来没啥问题, 改成这样试试

                    project(village_interfaces)
                    
                    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(sensor_msgs REQUIRED)
                    find_package(std_msgs REQUIRED)
                    find_package(rosidl_default_generators REQUIRED)
                    
                    # uncomment the following section in order to fill in
                    # further dependencies manually.
                    # find_package(<dependency> REQUIRED)
                    
                    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()
                    
                    #添加消息文件和依赖
                    rosidl_generate_interfaces(${PROJECT_NAME}
                      "msg/Novel.msg"
                      "srv/BorrowMoney.srv"
                      "srv/SellNovel.srv"
                       DEPENDENCIES std_msgs sensor_msgs 
                     )
                    ament_package()
                    
                    

                    另外还不行可以直接去掉

                    @andrew_liumuran 在 重新运行代码时出现:UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces' 中说:

                    sensor_msgs/Image image

                    新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

                    1 条回复 最后回复 回复 引用 0
                    • 小鱼小
                      小鱼 技术大佬 @andrew_liumuran
                      最后由 编辑

                      @andrew_liumuran 另外记得把build和install目录删除掉,重新colcon build试试

                      新书配套视频:https://www.bilibili.com/video/BV1GW42197Ck/

                      A 1 条回复 最后回复 回复 引用 0
                      • A
                        曼森的林佳树甜甜甜 @小鱼
                        最后由 编辑

                        @小鱼

                        謝謝小魚,刪除目錄有效,可以運行了!

                        1 条回复 最后回复 回复 引用 0
                        • 8421452488 842145248 在 中 引用了 这个主题
                        • 第一个帖子
                          最后一个帖子
                        皖ICP备16016415号-7
                        Powered by NodeBB | 鱼香ROS