摘要
本篇笔记记录了根据B站教程(ns3+VSCode开发环境配置完美版)配置NS3+VSCode开发环境的流程,在VSCode环境中实现NS3代码的代码智能提示、运行、调试。
资源
安装好了ns3+vs code的vmware workstation虚拟机
链接: https://pan.baidu.com/s/1UtTAOH4XtfPoByptILpmiA 提取码:7pi4
备用资源:
链接: https://pan.baidu.com/s/1oZCrNDrY7ZRxbo5Vf4PXzQ?pwd=6mht 提取码: 6mht
运行VSCode
首先,在ns3源码目录下启动Code:
root@ns3-vm:~ # cd ns-allinone-3.33/ns-3.33/
root@ns3-vm:~/ns-allinone-3.33/ns-3.33 # code . --user-data-dir=/root/.vscode-root
提示:以普通用户身份运行code时,不需要加“–user-data-dir=/root/.vscode-root”
代码智能提示
然后,在VS Code界面中,按F1(Ctrl+Shift+P)调出命令面板,配置相关设置“c/c++: Edit configurations(json)”:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/build/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
可以进行代码提示了!!!!
附:
虚拟机之与物理机进行文本的复制粘贴
配置build
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cpp build active file",
"command": "./waf",
"args": [],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/cpp"
}
]
}
按下ctrl+shift+b将调用waf进行编译
配置gdb调试
按F5,选择“C++(GDB/LLDB)” ,之后选择“waf - Build and debug active file compiler:/usr/bin/g++”:
使用F5调试模拟脚本,出错:提示找不到so库,解决方法:
执行如下命令,将ns3编译时生成的so文件复制到/lib目录下:
root@ns3-vm:~/ns-allinone-3.33/ns-3.33# cp build/lib/* /lib/
再次使用F5调试模拟脚本,Done!!!!
参考文档
https://www.bilibili.com/opus/494071708926899481?spm_id_from=333.1387.0.0