目的
盘了一块飞凌的RK3568开发板,想想用单纯用VIM开发就无比头疼,于是乎想来整一整vscode编译+远程调试的方案,提高工作效率。
需求
- vs code内可以编译
- 有代码提示,头文件提示
- 可以加外部链接库
- 远程调试比较好操作
实现
首先在虚拟机ubuntu环境下安装vscode. 这个没啥可说的,教程很多 我附加安装了这几个插件 插件安装完,接下来建一个简单的helloworld工程 注意: 我这里一并会把外部链接库的问题说了 我这里用libhv【一个高性能网络实现的库】的实现来举例说明 这里默认你的环境已经可以aarch64-linux-gnu-gcc 正常工作,而且可以通过交叉编译器交叉编译出libhv,并得到了外部库文件.a和.so 我的工程结构是这样的 其中lib文件夹下放编译出来的第三方库libhv的.a和.so hv文件夹是这个库的所有头文件引用 main.c是我测试的源文件 main是编译出来的文件 我接下来分享我vscode的上面几个重要的配置文件
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/home/forlinx/3568/OK3568-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/6.3.1/../../../../aarch64-linux-gnu/include/c++/6.3.1",
"/home/forlinx/3568/OK3568-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/6.3.1/../../../../aarch64-linux-gnu/include/c++/6.3.1/aarch64-linux-gnu",
"/home/forlinx/3568/OK3568-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/6.3.1/../../../../aarch64-linux-gnu/include/c++/6.3.1/backward",
"/home/forlinx/3568/OK3568-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/6.3.1/include",
"/home/forlinx/3568/OK3568-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/6.3.1/include-fixed",
"/home/forlinx/3568/OK3568-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/6.3.1/../../../../aarch64-linux-gnu/include",
"/home/forlinx/3568/OK3568-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../aarch64-linux-gnu/libc/usr/include",
"${workspaceFolder}/hv/**",
"${workspaceFolder}/lib/**"
],
"defines": [],
"compilerPath": "/home/forlinx/3568/OK3568-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
其中includePath包含编译器有关的include路径,第三方库的头文件引用,当前工作空间 compilerPath包含编译器的路径
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "OK3568_Gdb_Debugger",
"type": "cppdbg",
"request": "launch",
"program": "./main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/home/forlinx/3568/OK3568-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gdb",
"miDebuggerServerAddress": "192.168.8.10:6000",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
注意远程调试时 先要将编译好的main放到某个板卡的目录下,chmod修改权限为777 把编译出来的第三方库的so文件放到板卡文件系统的/lib下 启动gdbserver 我的启动命令行参考如下
gdbserver 192.168.8.12:6000 main
settings.json
{
"tasks": [
{
"type": "cppbuild",
"label": "RK3568_C文件编译",
"command": "/home/forlinx/3568/OK3568-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-L/home/forlinx/Test/lib",
"-lhv",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
},
{
"type": "cppbuild",
"label": "RK3568_C++文件编译",
"command": "/home/forlinx/3568/OK3568-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-L/home/forlinx/Test/lib",
"-lhv",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
注意第三方库的引用-L和-l的写法,库的名字是libhv.so,那么这里就要写-lhv,-L的写法我是写绝对路径的 更新下,方便切换编译C++文件或者C文件
完成上面的设置之后,在vs code下按F1,然后选运行任务,选OK3568_Gcc_compaire 如果编译无错误,应该VS下应该是这样的 然后需要把编译好的二进制执行文件传输到板卡上。这里方法很多,我这里是用sftp传过去,到某个文件夹下 再次强调 注意远程调试时 先要将编译好的main放到某个板卡的目录下,chmod修改权限为777 把编译出来的第三方库的so文件放到板卡文件系统的/lib下 启动gdbserver 我的启动命令行参考如下
gdbserver 192.168.8.12:6000 main
板子上运行效果如下 好了之后,在vs code这边打好断点,按F5,进入调试,成功效果如下 板子这边会变成这样 然后就可以开始调试了,单步,看变量状态等等。。。
|