C++ 静态库调试符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7575298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Static library debug symbols
提问by David
In VS2010 there is an option to generate debug info for exes/dlls under linkerbut no such option under librarianfor libs. Is the debug info embedded in the static library?
在VS2010存在是产生下的EXE / DLL的调试信息的选项链接,但在没有这样的选择图书管理员的库。调试信息是否嵌入到静态库中?
There is an option in the C/C++properties for Program Database File Namefor libs, exes, and dlls. By default it goes into my intermediate directory and is named the project name for libs, but is named vc$(PlatformToolsetVersion).pdbfor exes/dlls. What's the pdb from this option and how does it differ from the pdb in the linker option?
对于 libs、exes 和 dll,程序数据库文件名的C/C++属性中有一个选项。默认情况下,它进入我的中间目录,并为 libs 命名为项目名称,但为 exes/dll命名为vc$(PlatformToolsetVersion).pdb。此选项中的 pdb 是什么,它与链接器选项中的 pdb 有何不同?
If I am supplying a library with libs and headers how do I supply debug symbols to a user of my library?
如果我提供带有库和头文件的库,我该如何向库的用户提供调试符号?
采纳答案by mloar
If you use /ZI
or /Zi
(C/C++
-> General
-> Debug Information Format
), then the vc$(PlatformToolsetVersion).pdb
is created, which contains the debug info for all of the .obj
files created. If alternately you use /Z7
, the debug info will be embedded into the .obj
file, and then embedded into the .lib
. This is probably the easiest way to distribute the debug info for a static library.
如果您使用/ZI
or /Zi
( C/C++
-> General
-> Debug Information Format
),则会vc$(PlatformToolsetVersion).pdb
创建 ,其中包含所有.obj
创建的文件的调试信息。如果交替使用/Z7
,调试信息将嵌入到.obj
文件中,然后嵌入到.lib
. 这可能是分发静态库调试信息的最简单方法。
I wouldn't advise distributing a static library, however, since it's generally tied to a specific version of the compiler.
但是,我不建议分发静态库,因为它通常与编译器的特定版本相关联。
回答by bunkerdive
Expanding upon previous answers, for those who need the full how-to (VS 2013 minimum).
扩展以前的答案,适用于需要完整操作方法的人(最低 VS 2013)。
Note that this should address comments ^^above regarding VS2013 issues.
请注意,这应该解决上面关于 VS2013 问题的评论 ^^。
Method 1: The Program Database (.pdb) Way (/Zi or /ZI)
方法 1:程序数据库 (.pdb) 方式(/Zi 或 /ZI)
Static Lib Project: Generate a pdb with same name as your static lib:
- Open
Solution Explorer
from theView
menu. - Right click your static lib project, select
Properties
- Edit
Configuration Properties
->C/C++
->General
->Debug Information
to/Zi
or/ZI
- Note that
/ZI
allows "Edit and Continue" editing during debugging
- Note that
- Edit
Configuration Properties
->C/C++
->Output Files
->Program Database File Name
to$(OutDir)$(TargetName).pdb
- Now compile it, and note where YourLib.lib and YourLib.pdb are.
- Open
Application Project: Link your executable with the static lib, and new PDB file:
- Again, navigate to project properties, but this time, for your Application project
- Again, edit
Debug Information
property as needed. - Edit
Configuration Properties
->Linker
->General
->Additional Library Directories
, adding your own "libs" directory, or whatever directory you plan to keep/copy your YourLib.lib and YourLib.pdb files. - Edit
Configuration Properties
->Linker
->Input
->Additional Dependencies
, addingYourLib.lib
(no path in front) - Now copy both YourLib.liband YourLib.pdbto the directory you specified above.
静态库项目:生成与静态库同名的 pdb:
Solution Explorer
从View
菜单中打开。- 右键单击您的静态库项目,选择
Properties
- 编辑
Configuration Properties
->C/C++
->General
->Debug Information
到/Zi
或/ZI
- 请注意,
/ZI
允许在调试期间进行“编辑并继续”编辑
- 请注意,
- 编辑
Configuration Properties
->C/C++
->Output Files
->Program Database File Name
到$(OutDir)$(TargetName).pdb
- 现在编译它,并注意 YourLib.lib 和 YourLib.pdb 在哪里。
应用程序项目:将您的可执行文件与静态库和新的 PDB 文件链接起来:
- 再次导航到项目属性,但这次是针对您的应用程序项目
- 同样,
Debug Information
根据需要编辑属性。 - 编辑
Configuration Properties
->Linker
->General
->Additional Library Directories
,添加您自己的“libs”目录,或您计划保留/复制 YourLib.lib 和 YourLib.pdb 文件的任何目录。 - 编辑
Configuration Properties
->Linker
->Input
->Additional Dependencies
,添加YourLib.lib
(前面没有路径) - 现在将YourLib.lib和YourLib.pdb复制到您在上面指定的目录中。
Method 2: The Embedded Symbols (no .pdb) Way (/Z7)
方法 2:嵌入符号(无 .pdb)方式(/Z7)
Static Lib Project: Generate a static lib with embedded debug symbols
- As in Method 1, navigate to project properties
- As in Method 1, modify your
Debug Information
, but this time to/Z7
- As in Method 1, compile and note where YourLib.lib is generated.
Application Project: Link you executable with the static lib
- As in Method 1, navigate to project properties
- As in Method 1, modify your
Debug Information
property as needed - As in Method 1, edit
Additional Library Directories
- As in Method 1, edit
Additional Dependencies
- Now copy YourLib.lib to the directory specified in
Additional Library Directories
静态库项目:生成带有嵌入调试符号的静态库
- 与方法 1 一样,导航到项目属性
- 与方法 1 一样,修改您的
Debug Information
,但这次是/Z7
- 与方法 1 一样,编译并注意生成 YourLib.lib 的位置。
应用程序项目:将您的可执行文件与静态库链接
- 与方法 1 一样,导航到项目属性
- 与方法 1 一样,
Debug Information
根据需要修改您的属性 - 与方法 1 一样,编辑
Additional Library Directories
- 与方法 1 一样,编辑
Additional Dependencies
- 现在将 YourLib.lib 复制到指定的目录中
Additional Library Directories
Discussion:
讨论:
- Advantages of Z7?It's simpler, and the "Single-file" way of doing it. All the debug info is in the lib file.
- Disadvantages of Z7?File size on-disk, link times, incompatible with "Minimal rebuild" (/Gm) feature, does notallow "Edit and Continue", older format (e.g. older paradigm)
- Why don't I specify
Debug Information
Setting for Application Project?This post is concerned with how to get debug working in static lib code. The same "Method 1 vs Method 2" choice applies for the Application project as well.
- Z7的优势?它更简单,而且是“单文件”方式。所有调试信息都在 lib 文件中。
- Z7的缺点?文件大小在磁盘上,连接时间,用“最少重建”不兼容(/ GM)功能,不会让“编辑并继续”,旧的格式(例如,旧的范式)
- 为什么我不指定
Debug Information
应用程序项目的设置?这篇文章关注如何在静态库代码中进行调试。相同的“方法 1 与方法 2”选择也适用于应用程序项目。
回答by MilesDavies192
I notice in VS2013 it is possible to set the program database file name in the C/C++ Output Files tab. Changing it from the default to something like $(OutDir)$(TargetName).pdbresolves the issue
我注意到在 VS2013 中可以在 C/C++ 输出文件选项卡中设置程序数据库文件名。将其从默认值更改为$(OutDir)$(TargetName).pdb 之类的内容可以解决该问题
回答by Pubby
Static libraries are implemented into the programs that use them.
静态库被实现到使用它们的程序中。
If the program that uses them is using debug symbols, the compiled library code in that program will have symbols too.
如果使用它们的程序正在使用调试符号,则该程序中已编译的库代码也将具有符号。
PDB info from wikipedia:
来自维基百科的 PDB 信息:
When debug symbols are embedded in the binary itself, the file can then grow significantly larger (sometimes by several megabytes). To avoid this extra size, modern compilers and early mainframe debugging systems output the symbolic information into a separate file; for Microsoft compilers, this file is called a PDB file.
当调试符号嵌入到二进制文件本身中时,文件会变得更大(有时会增加几兆字节)。为了避免这种额外的大小,现代编译器和早期的大型机调试系统将符号信息输出到一个单独的文件中;对于 Microsoft 编译器,此文件称为 PDB 文件。
回答by nothrow
Weird behavior in VS2012. Building from scratch (or with /A option in nmake) will produce a .pdb file. Now delete the .lib and .pdb and rerun nmake (without /A of course, to run only link) and no .pdb file is output.
VS2012 中的奇怪行为。从头开始构建(或使用 nmake 中的 /A 选项)将生成一个 .pdb 文件。现在删除 .lib 和 .pdb 并重新运行 nmake(当然没有 /A,只运行链接)并且没有输出 .pdb 文件。