调试在Visual Studio Code中使用makefile构建的c++
Debugging c++ built with a makefile in Visual Studio Code
我有一个现有的代码库,构建一个makefile,我想使用Visual Studio code来运行它。
我首先用Visual Studio Code打开我的项目目录。然后,为了构建,我按照http://code.visualstudio.com/docs/languages/cpp:
创建了一个任务。{
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args":["-c", "cd build && make"]
}
可以正常工作。然后我下载了c++扩展并创建了一个launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x64",
"program": "${workspaceRoot}/build/myProgram",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb"
}
},
// attach here, which I don't care about
]
}
这个启动文件允许我使用内置调试器启动程序。我知道它是有效的,因为我看到所有的符号文件被加载,我可以暂停程序。
然而,VS Code不"看到"我的源文件;当我暂停时,它显示
Source /Unknown Source is not available.
我也不能在源代码中设置断点。我看到一些符号被加载,尽管当我暂停执行时,我可以在调用堆栈上看到我的函数名。
我错过了什么?我绝对要做的,因为他们说在这里(http://code.visualstudio.com/docs/languages/cpp),并使一个g++任务,我将不得不手动输入所有我的包括路径和链接器的输入?首先使用makefile的意义在于不必做这些繁琐的事情…
非常感谢那些知道如何处理VS代码的人
您应该能够通过使用tasks.json
和launch.json
进行调试。
你确定你有-g
选项设置在你的makefile?
另一件事-你可以让你的任务在启动时执行添加"preLaunchTask": "bash"
到你的launch.json
.
希望这对你有帮助!
At windows;Mingw
, gdb
和-g
参数在编译可执行文件时是c/c++扩展所必需的。launch.json
中不需要"preLaunchTask": "bash"
相关文章:
- 如何在使用Makefile构建后在cmd中运行该程序?
- 使用 bazel 构建 Makefile
- 使用 Makefile 构建共享库
- 通过构建配置创建makefile
- 构建Makefile的问题
- 在makefile中更改构建规则以构建多种文件类型
- 在应用程序中使用不同的文件夹构建makefile
- 一个简短的c++文件和makefile:我可以在shell中制作,但在Eclipse中构建它时会遇到很多错误
- 使用 Makefile.am/Makefile.in 在 Ubuntu Linux 中构建 c++ 项目
- 使用 Makefile 构建 qt 类时链接失败
- EclipseCDT-带有现有代码的新Makefile项目-更改全局默认构建目标
- 在windows中用makefile构建一个c++程序
- Makefile:强制项目在构建时使用动态或静态库
- 使用一个Makefile构建多个共享库
- 使用Makefile构建:即使明确指定,也会选择file.c而不是file.cpp
- GNU make: Makefile一次构建多个.cpp文件
- Makefile构建共享库
- 用Makefile构建cuda和boost库
- 调试在Visual Studio Code中使用makefile构建的c++
- c++ makefile构建多个dll和项目结构