这里解释说 clang 现在知道如何生成 .pdb 文件(http://blog.llvm.org/2017/08/llvm-on-windows-now-supports-pdb-debug.html)。
据我所知,至少 clang 与 Microsoft 链接器现在预计会生成与 msvc 工具链生成的文件等效的 .pdb 文件。
此处解释了如何使用主流 Visual Studio 2017 调试“外部”二进制文件,即不是使用项目/解决方案构建的二进制文件 (https://learn.microsoft.com/en-us/visualstudio/debugger/how-to-debug-an-executable-not-part-of-a-visual-studio-solution)。
我用 clang -g main.c -o main.exe
编译了一个简单的 hello world 应用程序,它按预期生成了一个 .pdb 文件。
但是,当我尝试进入它时,Visual Studio 提示 .pdb 文件不包含行号信息。
相比之下,使用 cl/EHsc/Zi main.c
编译允许使用 Visual Studio 正常调试。
我目前正在尝试了解 clang 生态系统是否已经足以在 Windows 上进行开发,如果有人能解释一下,我将不胜感激:
- stable clang 和 msvc 生成的 .pdb 文件有什么区别?
- 在这方面,
link
和lld
之间有什么区别吗? - clang 6.0 会发生变化吗?
最佳答案
这对我有用:
clang -g -gcodeview main.c -o main.exe
选项-gcodeview
告诉Clang 在Microsoft 的CodeView format 中生成调试信息。 .
然后 Visual Studio 可以毫无问题地读取生成的 .pdb
。
另一种选择是使用 clang-cl
,您可以将 /Zi
传递给它,或者 MIEngine ,这应该允许您在 Visual Studio 中使用非 CodeView 调试信息。
不过,我还没有尝试过这两种方法。
郑重声明,这是我的 main.c:
#include <stdio.h>
int main() {
getc(stdin); // pause to allow attaching the debugger
return 0;
}
我用了Clang 6.0.0 .
关于c++ - 截至 2017 年的 clang 5.0 pdb 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47858889/