CLion远程Docker调试ROS(交叉编译)的设置步骤
-
准备一个好用的docker,运行起来(Docker Image一定可以跑cuda和图形界面的,否则启动不了CLion,可以不用浪费时间看本教程了)
-
在docker镜像中配置好ssh和rsync,我的 /etc/ssh/sshd_config 配置是:
Port 2222
PasswordAuthentication yes
PermitEmptyPasswords no
PermitRootLogin yes
UsePAM no
Subsystem sftp internal-sftp
Match Group remote_user
ChrootDirectory /
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
启动镜像后,建议重新启动ssh和rsync,否则比较容易出错,有好的建议可以评论交流哈~
service ssh restart
service rsync restart
- 先用CLion 在docker里面 下载CLion EAP,如图
下载好之后,点进去,会弹出权限不够, Read-Only问题,容易卡在这里,推不下去。
之所以要推,是因为需要用ROS1生成的CMakeLists.txt文件,而该文件是一个软链接,不是实际的文件,本地Local CLion环境无法Load,显示
CMakeLists.txt not found in /home/shanph/Documents/ros1_ws/cross_ws/src Select CMakeLists.txt
[Failed to reload]
而docker已经安装好ROS和交叉编译环境,所以需要docker里面的环境来启动之后可以用CLion编译和调试,但是配置了CLion的Tools里面development,无数次重置SFTP和Resync都不行之后,只能另辟蹊径了,网上的资料也很少。
解决办法
- 找到上述步骤3中下载的CLion EAP在docker中的存放位置,一般是/home/<user_name>文件夹下的.cache文件夹,比如我就是:
/home/remote_user/.cache/JetBrains/RemoteDev/dist/f8ec2e0a71d00_CLion-231.7665.29/bin
-
进入该文件夹,直接在Docker Terminal中启动./clion.sh,注意不要在PC上操作,而且Docker需要支持图形界面显示,否则无法启动
-
启动之后打开Project,设置好cmake选项就可以Enjoy your self了,具体配置贴一下,需要用env.sh来配置CLion环境才可以直接用IDE编译和调试ROS程序。
CMAKE_PREFIX_PATH=/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/aarch64-rockchip-linux-gnu/sysroot:/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/aarch64-rockchip-linux-gnu/sysroot/usr:/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/aarch64-rockchip-linux-gnu/sysroot/opt/ros/indigo/;LD_LIBRARY_PATH=/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/aarch64-rockchip-linux-gnu/sysroot/lib:/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/aarch64-rockchip-linux-gnu/sysroot/usr/lib:/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/aarch64-rockchip-linux-gnu/sysroot/opt/ros/indigo/lib;PKG_CONFIG_PATH=/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/aarch64-rockchip-linux-gnu/sysroot/usr/lib/pkgconfig:/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/aarch64-rockchip-linux-gnu/sysroot/opt/ros/indigo/lib/pkgconfig;PYTHONPATH=/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/aarch64-rockchip-linux-gnu/sysroot/usr/lib/python2.7/site-packages:/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/aarch64-rockchip-linux-gnu/sysroot/opt/ros/indigo/lib/python2.7/site-packages:/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/lib/python2.7/site-packages;ROS_DISTRO=indigo;RosToolchainRoot=/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host;PATH=/home1/heweihong/workspace/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/bin:/home1/heweihong/workspace/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/opt/ros/indigo/bin:/home/shanph/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/binv
-DCMAKE_TOOLCHAIN_FILE=/workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/RosToolchain.cmake
source /workspace/hewh10/robot/rk3566/buildroot/output/rockchip_rk3566_midea/host/RosToolchainSetup.bash && catkin_make -j24 -DCMAKE_TOOLCHAIN_FILE=$ROS_CMAKE_TOOLCHAIN_FILE 2>&1 | tee log.txt
- Tips
在Docker Terminal编译过程中产生的文件如果直接用CLion编辑会提示权限不够,需要在Docker Terminal中对文件进行赋权操作。
chown -R root file_name
错误的赋权会导致CLion编译出错,所以要比较精确的进行赋权。
- DONE。