简体   繁体   English

使用Visual Studio 2013为本地DLL正确生成PDB文件

[英]Generating PDB files correctly for a native DLL using Visual studio 2013

Yesterday, I went through our company's projects and updated them to fix a mistake (AFAIK) in how we configured them. 昨天,我浏览了我们公司的项目,并对其进行了更新,以解决如何配置它们的错误(AFAIK)。

The issue was that under the property pages for the projects, under Configuration Properties -> C/C++ -> Output Files , we set Program Database File Name to $(OutDir)$(TargetName).pdb , the same value we had set Configuration Properties -> Linker -> Debugging -> Generate Program Database File . 问题在于,在项目的属性页下的“ Configuration Properties -> C/C++ -> Output Files ,我们将“ Program Database File Name设置为$(OutDir)$(TargetName).pdb ,该值与我们设置“ Configuration Properties -> Linker -> Debugging -> Generate Program Database File相同 Configuration Properties -> Linker -> Debugging -> Generate Program Database File

My understanding is that the first property sets the location of the pdb file which contains symbols for the object files created during compilation of the source, while the second sets the location of the pdb file which contains symbols for the generated DLL. 我的理解是,第一个属性设置pdb文件的位置,该文​​件包含在源代码编译期间创建的目标文件的符号,而第二个属性设置pdb文件的位置,其中包含用于生成的DLL的符号。 Is that correct? 那是对的吗?

Under this assumption, to prevent them from conflicting (I assume this is unwanted) I set the first property to $(IntDir)$(TargetName).pdb , but this broke the resulting pdb file (ie a debugger doesn't recognize it as the DLL's pdb file, and a co-worker ran a tool on it, and the signature does not match the one contained in the binary). 在这种假设下,为防止它们发生冲突(我认为这是不必要的),我将第一个属性设置为$(IntDir)$(TargetName).pdb ,但这会破坏生成的pdb文件(即调试器无法将其识别为DLL的pdb文件,并且同事在其上运行了一个工具,并且签名与二进制文件中包含的签名不匹配)。

The strange thing is that using the value $(IntDir)$(TargetName)2.pdb (note the '2' suffix) fixes the issue. 奇怪的是,使用值$(IntDir)$(TargetName)2.pdb (注意后缀2)解决了该问题。 I don't understand why the name of the intermediate file would matter? 我不明白为什么中间文件的名称很重要?

Note that Configuration Properties -> C/C++ -> General -> Debug Information Format is set to Program Database (/Zi) 请注意, Configuration Properties -> C/C++ -> General -> Debug Information Format设置为Program Database (/Zi)

I'd say you got it right: the compiler produces object files. 我想说的没错:编译器生成目标文件。 At that time the DLL is not ready yet, so whatever that PDB file contains, it's not helpful in debugging. 那时DLL还没有准备好,所以无论PDB文件包含什么,它都对调试没有帮助。

After the linker has processed the output of the compiler, the DLL exists. 链接器处理了编译器的输出后,该DLL存在。 At that time, a PDB makes sense for debugging. 那时,PDB对于调试很有意义。 So the relevant file for debugging purposes is in Linker -> Debugging -> Generate Program Database File . 因此,用于调试目的的相关文件位于Linker -> Debugging -> Generate Program Database File

As @HansPassant mentioned in the comments, the Compiler setting should not be touched. 正如@HansPassant在评论中提到的那样,不应更改编译器设置。 Too bad it already happened. 太糟糕了,它已经发生了。 In a Visual Studio 2013 or 2015 C++ console application, the default value for C/C++ -> Output Files is $(IntDir)vc$(PlatformToolsetVersion).pdb , so the final name is something like Debug\\vc120.pdb or Debug\\vc140.pdb . 在Visual Studio 2013或2015 C ++控制台应用程序中, C/C++ -> Output Files的默认值为$(IntDir)vc$(PlatformToolsetVersion).pdb ,因此最终名称类似于Debug\\vc120.pdbDebug\\vc140.pdb

IMHO, changing the compiler's output file should not matter, as long as the name does not conflict with the linker setting. 恕我直言,只要名称不与链接器设置冲突,更改编译器的输出文件就没有关系。 That's exactly what happened to you: the compiler name $(IntDir)$(TargetName).pdb (relative path) resolves to the same file as the linker name $(OutDir)$(TargetName).pdb (absolute path). 这就是发生的事情:编译器名称$(IntDir)$(TargetName).pdb (相对路径)解析为与链接器名称$(OutDir)$(TargetName).pdb (绝对路径)相同的文件。 In that case it may happen that the linker cannot write to the file because it's still in use by the compiler or other strange things. 在这种情况下,链接器可能无法写入文件,因为编译器或其他奇怪的东西仍在使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM