如何在大型c++项目的可视化代码中设置调试
How do I set up debugging in visual code for a large c++ project
我是c++和vs代码的初学者,但我的任务是使用/开发现有的c++项目(在此之前我使用过python和sublime)。
我希望能够配置vs代码,这样我就可以轻松地调试和编译代码,而不会有太多麻烦。
目前,我是这样做的:
- 对代码进行一些更改,例如在$basedir/src/folder1/file.cpp中
- 转到终端中的$basedir,然后运行
- a) 制造
- b)等待它浏览一堆文件夹,找到一个已更改的文件
- c) cd$basedir/programs/dawn;清洁;制造
- 最后运行一个类型的项目:
$basedir/programs/project/projectname inputfile.json
我想做的是只按F5(用于调试,或ctrl+F5运行),但我不知道如何设置所有内容。有人能帮我吗?
这些是我的配置文件:在c_cpp_properties.json中,我引用了另外两个项目,但我也必须添加当前项目的include目录,以便vs代码不会抱怨include文件等(我以为它会自动在带有${workspaceFolder}/**
的项目中找到文件)
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"~/otherproject1/include/",
"~/otherproject2/include/",
"~/Documents/projectname/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
{
tasks.json
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"cd ${workspaceFolder};",
"make;",
"make clean -C programs/projectname;",
"make -C programs/projectname;",
],
"options": {
"cwd": "/usr/bin"
}
}
],
"version": "2.0.0"
}
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/programs/projectname inputfile.json",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
Microsoft为设置调试环境提供了很棒的教程。
请查看以下教程:
VSCode CPP调试
配置mingW和GCC调试
在您的配置中显而易见的是,您错过了此处的.exe
"program": "${fileDirname}/${fileBasenameNoExtension}", //< -- wrong
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", // < -- correct
找到你的调试器并在这里添加路径:
"miDebuggerPath": "C:\path\to\gdb.exe",
要开始调试,只需点击F5
。对于"构建",请单击CTRL + SHIFT + B
并选择您的构建任务。
相关文章:
- 如何在大型c++项目的可视化代码中设置调试
- 如何使用可视化代码和平台IO将环境变量注入CPP文件?
- 如何在可视化代码中生成用于 c++ 开发的调试器?
- 可视化配置 VS 代码以进行 C++ 编程和开发
- 可视化的c++变量赋值使代码正常工作
- 使用.natvis文件可视化VS代码中的C++对象
- 可视化C++显式模板定义 - 代码仍重复
- 在Visual Studio 2019中构建简单的点云可视化代码时,来自PCL的第三方库的多个错误
- 可视化优雅C++代码:如何使用 while 循环和条件语句编写更高效的代码
- 可视化如何使用C++程序获取DHCPV6服务器IP.我尝试使用DHCPv6RequestParams,但总是收到错误代码
- 我无法使用可视化工作室代码构建C++
- 在 64 位 debian 上编译 GCC 的代码可视化补丁
- 可视化C++ 使用较新编译器的功能生成供较旧编译器使用的代码
- 将 XSD 转换为 C++ 代码的可视化工具
- 可视化在线运行C++代码
- 可视化C++代码文档:doxygen vs 内置于 VC++ 编译器中
- 可视化设置一个c++应用程序使用最大CPU使用率,在代码中
- 可视化地将C++代码从一个程序转移到另一个程序
- 有没有可以可视化c++代码结构的程序?
- 可视化C++代码加密,无需使用密码或密钥