发布/调试地狱,使用 V-studio C++项目
我对这种事情的发生感到非常厌倦。我正在使用 C++ 在 Visual Studio 中工作,并且在尝试发布构建/运行周期之前在开发中进行了一些尝试,结果发现我的发布构建崩溃了。除了破解大块代码来寻找所有潜在的违规者之外,我没有办法解决这个问题。无论如何,如果我进入“发布”项目属性并启用“编辑并继续”的调试数据库,并且甚至不在链接器中启用调试,则发布版本可以完美运行。
好的,我非常感谢任何关于要寻找什么样的东西才能使我的发布版本正常工作的意见,但我敢问这个问题:“谁在乎”?据我了解,如果链接器确实与运行时和 Windows 库的调试版本链接,则该程序可能无法在任何未安装 VStudio 的系统上运行。但是我正在做的事情呢......只是让编译器 DEBUG 格式设置为“用于编辑和继续的程序数据库(/ZI)”。它在应用程序的大小方面几乎没有 1K 的差异,如果它不会阻止 EXE 工作,也许我应该保持这种设置?还是我自找麻烦?
——兰迪
I'm so tired of this happening. I'm working in Visual studio using C++, and go a little to far in developemnt before attempting a release build/run cycle, only to find my release build crashes. It leaves me no way to fix the problem beyond to hack out big chunks of code looking for all potential violators. Anyway, If I go into my "release" project properties and enable the debug database for "Edit and Continue", and DON'T even enable Debugging in the linker, the Release version runs perfectly.
OK, I do appreciate any input as to what kinds of thing to look for to properly get my Release version to work, but dare I ask this question: "Who Cares"? I understand that if the linker does in fact link with DEBUG versions of runtime and windows libraries, that the program probably won't run on any system that doesn't have VStudio installed. But what about what I'm doing... just letting the compiler DEBUG format set to "Program Database for Edit & Continue (/ZI)". It hardly makes a 1K difference in the sixze of the application, and if it won't stop the EXE from working, maybe I should just leave it set that way? Or am I asking for trouble?
--Randy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
“谁在乎?” ...好吧,你应该。
发布版本崩溃的事实表明它存在问题。
如果打开调试符号可以“修复”它,那么您就得到了一个您不理解的神奇修复。为什么它能修复它?您可以信赖此修复程序适用于安装了您的软件的每台电脑吗?
您描述的症状表明您正在某处损坏内存(最有可能是缓冲区溢出错误),并且添加调试符号会重新排列或填充您的代码,这样您就可以“摆脱它”,因为内存损坏不会“不要碰巧撞到任何重要的东西。
但你不能真正依赖这样的修复。它会破坏您对应用程序的所有信心,并且有一天它会咬住您(这样的修复很容易在您下次编译应用程序时停止“工作”)
您需要隔离导致此问题的原因问题 - 如果它发生多次,那么你就没有从上次修复它时学到任何东西。应用程序在调试中运行而不是在发布中运行是不“正常”的,因此一定是您做错了什么 - 您需要弄清楚它是什么并修复它,以便将来避免此类错误。 (例如,如果是缓冲区溢出,则可能只是您分配了“n”个元素的缓冲区,然后访问元素“n” - 您应该只访问元素 0 到 (n-1)。这很容易修复一次你知道如何编写这样的代码......但是你必须付出一些努力来找出你做错了什么)
"Who cares?" ... well, you should.
The fact that the release build crashes indicates there is something wrong with it.
If turning on debug symbols "fixes" it, then you have a magic fix that you don't understand. Why does it fix it? Can you rely on this fix working on every PC your software is installed on?
The symptoms you describe suggest that you are corrupting memory somewhere (a buffer overrun error most likely) and that addition of debugging symbols rearranges or pads out your code in such a way that you can "get away with it" because the memory corruption doesn't happen to hit anything vital.
But you can't really rely on such a fix. It undermines all confidence in your application, and it will bite you one day (such a fix could easily stop "working" the next time you compile your app)
You need to isolate what it is that causes this problem - if it happens more than once then you haven't learned anything from the last time you fixed it. It's not "normal" for an application to run in debug but not in release, so there must be something you're doing wrong - you need to work out what it is and fix it so that you avoid such bugs in future. (e.g. If it's a buffer overrun it may simply be that you are allocating a buffer of "n" elements and then accessing element "n" - you should only access elements 0 to (n-1). THis is very easy to fix once you understand how to write such code... but you have to put in a bit of effort to work out what it is youre doing wrong)
我认为您需要确定哪些实践/代码会导致调试崩溃而不是发布崩溃。
如果你能弄清楚这一点,你就能确定你需要采取哪些不同的做法。
此外,“我正在使用 C++ 在 Visual Studio 中工作,并且在尝试发布构建/运行周期之前在开发方面走得有点远”,这对我来说表明您可能希望在开发实践中制定更多规则。您可能想花一些时间学习一些测试驱动的开发技术;我发现这些提高了我的代码/编译缺陷率。
I think you need to identify what practices/code you have that cause crash in Debug but not Release.
If you can figure that out, you can identify what you need to do differently.
In addition, "I'm working in Visual studio using C++, and go a little to far in developemnt before attempting a release build/run cycle" indicates to me that you might want to develop more discipline in your development practice. You might want to spend a bit of time learning some test-driven development techniques; I found that those improved my code/compile defect rates.
我使用单个构建而不是单独的调试和发布构建:请参阅“单独的‘调试’和‘发布’构建?
”通常调试和发布版本之间存在一些差异,例如:
事实上,您可以任意组合使用它们。唯一会阻止您的软件在干净的计算机上运行的方法是使用运行时库的调试版本。
我通常会关闭编辑并继续以及增量链接,因为我发现这些在很久以前就存在错误。
I use a single build instead of separate debug and release builds: see "Separate ‘debug’ and ‘release’ builds?"
There are normally several differences between debug and release builds, e.g:
You can in fact use these in any combination. The only thing that would stop your software running on a clean machine would be using the debug versions of the run-time libraries.
I usually switch off edit-and-continue, and incremental linking, because I've found these to be buggy in the distant past.
是的,你是在自找麻烦。从表面上看,您正在编写包含未定义行为的代码,并且碰巧(至少看起来)在某些情况下工作 - 但它仍然几乎肯定是错误的(是的,一些编译器有优化错误,因此正确的代码不会)优化后不起作用——但这种情况相当罕见)。
Yes, you're asking for trouble. From the sound of things, you're writing code that contains undefined behavior, and happens to (at least appear to) work under certain circumstances -- but it's still almost certainly wrong (yes, some compilers have optimization bugs so correct code doesn't work when optimized -- but these are fairly rare).