1. C++
Linux上建议用cmake编译,然后用vscode调试,所以只需修改launch.json这个文件
,然后点击Run->Start Debugging进行调试
1.1. launch.json文件
打开方式:Run->Open Configurations
{"version": "0.2.0","configurations": [{"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示"type": "cppdbg", // 配置类型,这里只能为cppdbg"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)"launchOptionType": "Local", // 调试器启动类型,这里只能为Local"targetArchitecture": "x86", // 生成目标架构,一般为x86或x64,可以为x86, arm, arm64, mips, x64, amd64, x86_64"program": "${workspaceFolder}/text.out", // 将要进行调试的程序的路径"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,一般设置为false"cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceRoot}即代码所在目录"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台"preLaunchTask": "g++", // 调试会话开始前执行的任务,一般为编译程序,c++为g++, c为gcc"MIMode": "gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true}]}]
}
如果不用VSCode进行编译,则需要把preLaunchTask取消,建议参考下面文件
{"version": "0.2.0","configurations": [{"name": "g++ build and debug active file","type": "cppdbg","request": "launch","program": "${workspaceFolder}/bin/opencv_test", // 可执行文件路径"args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true}],"miDebuggerPath": "/usr/bin/gdb"}]}
1.2. task.json文件
{"version": "0.1.0","command": "g++","args": ["-g","${file}","-o","${file}.exe"], // 编译命令参数"problemMatcher": {"owner": "cpp","fileLocation": ["relative", "${workspaceRoot}"],"pattern": {"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$","file": 1,"line": 2,"column": 3,"severity": 4,"message": 5}}
}
2. Python
{"configurations": [{"name": "nerfacto","type": "python","request": "launch","program": "${workspaceFolder}/nerfstudio/scripts/train.py","args": ["nerfacto", "--data", "/data/nerfstudio/posters_v3"],"console": "integratedTerminal"}]
}
参考文献
vscode中launch.json配置项解释_vscode中写launch里面哪一个需要注释-CSDN博客
Get Started with C++ on Linux in Visual Studio Code
Ubuntu系统下使用VS Code编译调试C++程序并添加外部库_vscode添加c++第三方库-CSDN博客