关于在创建C++节点和功能包时,colcon build失败

在创建单个节点后,运行colcon build报错:

Starting >>> demo_cpp_pkg
Starting >>> demo_python_pkg
--- stderr: demo_cpp_pkg                                              
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status
gmake[2]: *** [CMakeFiles/cpp_node.dir/build.make:151:cpp_node] 错误 1
gmake[1]: *** [CMakeFiles/Makefile2:137:CMakeFiles/cpp_node.dir/all] 错误 2
gmake: *** [Makefile:146:all] 错误 2
---
Failed   <<< demo_cpp_pkg [0.42s, exited with code 2]
Aborted  <<< demo_python_pkg [0.43s]

Summary: 0 packages finished [0.58s]
  1 package failed: demo_cpp_pkg
  1 package aborted: demo_python_pkg
  1 package had stderr output: demo_cpp_pkg

首先按照提示检查下cpp文件的main函数定义是否正确,其次检查下CMakeists.txt是否有正确到如来rclrpp依赖。

经检查后,上述两个问题都没有问题。那就可以猜测是编译缓存导致的:

1.在终端进入工作空间
2.rm -rf build install log #清除缓存文件
3.colcon build --cmake-clean-cache  # 重新编译

经上述操作后,功能包成功被创建:

[0.149s] WARNING:colcon.colcon_ros.prefix_path.ament:The path '/home/ljy/chapt2/install/demo_python_pkg' in the environment variable AMENT_PREFIX_PATH doesn't exist
Starting >>> demo_cpp_pkg
Starting >>> demo_python_pkg
Finished <<< demo_python_pkg [0.46s]                             
Finished <<< demo_cpp_pkg [2.52s]                    

Summary: 2 packages finished [2.66s]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值