简体   繁体   English

如何在Visual Studio中调试库的发行版本

[英]how to debug a release version of library in Visual Studio

I need to debug the release version of my linked library. 我需要调试链接库的发布版本。 I am already generating debug information with my release build following this article but how can I do the same with the library project? 我已经在本文之后使用我的发布版本生成调试信息,但是我如何对库项目执行相同的操作? Note that library project doesn't have link page in properties where debug information is created in the link above. 请注意,库项目在属性中没有链接页面,其中在上面的链接中创建了调试信息。 I am using VS2010. 我正在使用VS2010。

What I really want is to make TRACE work whlile debugging the library. 我真正想要的是让TRACE在调试库时工作。 I tried to link debug version of library with the release exe but it creates linker errors. 我试图将调试版本的库与发布exe链接,但它会创建链接器错误。

What I really want is to make TRACE work... 我真正想要的是让TRACE工作......

You mean the MFC TRACE macro? 你的意思是MFC TRACE宏? The one that writes messages to the debug/output window of the debugger? 将消息写入调试器的调试/输出窗口的那个?

Unfortunately, even if you do fix your build settings so that your final executable contains debug information for your static library it won't bring back those trace statements. 不幸的是,即使您确实修复了构建设置,以便最终的可执行文件包含静态库的调试信息,它也不会带回那些跟踪语句。 TRACE is a macro and therefore is handled by the compiler preprocessor. TRACE是一个宏,因此由编译器预处理器处理。 When you compile in release mode, that macro is redefined to be a no-op. 在发布模式下编译时,该宏被重新定义为无操作。 It's as if the TRACE statement was deleted from the source code. 就像从源代码中删除了TRACE语句一样。

Even if you do resolve the problem of adding debug symbols to your library and executable, it won't bring those trace statements back. 即使您确实解决了向库和可执行文件添加调试符号的问题,也不会将这些跟踪语句带回来。 They were removed during the compile phase. 它们在编译阶段被删除。

So what to do? 那么该怎么办? Turns out, if you dig deep enough into those macros, they are ultimately calling a Win32 function OutputDebugString . 事实证明,如果你深入挖掘这些宏,他们最终会调用Win32函数OutputDebugString This call is available in both debug and release versions of the ms libraries. 此调用在ms库的调试版和发行版中都可用。 So ... you could replace the trace macros with explicit calls to OutputDebugString - it's not as convenient to code with but at least you will get your debug output in release mode. 所以...你可以用对OutputDebugString的显式调用来替换跟踪宏 - 编写代码并不方便,但至少你会在发布模式下获得调试输出。

BTW, I finally gave up on all those macros years ago and we have completely replaced them with log4cplus calls. 顺便说一句,几年前我终于放弃了所有这些宏,我们已经用log4cplus调用完全替换了它们。 Any logging framework would be better than the trace macros - because the time when you really need tracing is not when you are debugging but when your code is in production and you cannot reproduce the problem locally. 任何日志记录框架都会比跟踪宏更好 - 因为您真正需要跟踪的时间不是在您调试时,而是在您的代码处于生产状态而您无法在本地重现问题时。 It's much better to log to a file which the customer can send to you, then rely on tracing that only works in the debugger. 记录客户可以发送给您的文件要好得多,然后依靠只能在调试器中工作的跟踪。 Something to consider anyways... 无论如何要考虑的事情......

A static library isn't linked, so it's no surprise that linker options are unavailable. 静态库没有链接,因此链接器选项不可用也就不足为奇了。 You basically just need to tell the compiler to produce debugging information. 您基本上只需要告诉编译器生成调试信息。 From there, creating the library is little more than putting a bunch of object files together into a single file. 从那里开始,创建库只不过是将一堆目标文件放在一个文件中。

So basically, just tell the compiler to produce debug information, and the library will contain debug info. 基本上,只需告诉编译器生成调试信息,该库将包含调试信息。

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

相关问题 调试和发布库链接与 CMAKE (VISUAL STUDIO) - Debug and Release Library Linking with CMAKE (VISUAL STUDIO) 在Visual Studio中链接发布中的库和调试中的.exe崩溃 - Linking against library in release and .exe in debug crashes in Visual studio Visual Studio发行版和调试的区别 - Visual Studio Release and Debug difference 为什么发布版本的内存集比Visual Studio 2012中的调试版本慢? - why the release version memset is slower than debug version in visual studio 2012? 如何检测Qt Creator的目标(调试/发布)(Visual Studio) - How to detect Qt Creator's target (debug/release) (Visual Studio) 运行时如何在 Visual Studio C++ 中确定调试或发布模式 - Runtime how to determine Debug or release mode in visual studio c++ 如何在CMake for Visual Studio中获取当前配置(发布/调试) - How to get current configuration (Release/Debug) in CMake for Visual Studio CMake visual studio调试/发布配置 - CMake visual studio debug/release config 在 Visual Studio Code 中定义 DEBUG 和 RELEASE 符号 - Define DEBUG and RELEASE symbols in Visual Studio Code / MT版本的Visual Studio 2008中的二进制崩溃-如何调试 - /MT version of binary crashes in Visual Studio 2008 - how to debug
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM