我可以在STL中禁用异常吗

我可以在STL中禁用异常吗

本文介绍了我可以在STL中禁用异常吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的C ++应用程序中禁用异常,在MSVC下编译。我切换了选项启用C ++异常为NO,但我收到警告告诉我使用选项/ Ehsc,我不想。

I want to disable exceptions in my C++ aplication, compiled under MSVC. I hve switched the option Enable C++ exceptions to NO, but I get warnings telling me to use the option /Ehsc, which I dont want to.


我的代码中没有try / catch块, 。我发现使用宏定义_HAS_EXCEPTIONS = 0应该禁用STL中的异常,但我仍然得到如下警告:

I do not have try/catch blocks in my code, but I use STL. I have found that using macro definition _HAS_EXCEPTIONS=0 should disable the exceptions in STL, but I am still getting warning like:


警告C4275:非dll接口类'stdext :: exception'用作dll接口的基类class'std :: bad_typeid'
参见声明'stdext :: exception'
查看std :: bad_typeid的声明


有什么方法如何关闭例外是STL?

Is there any way how to switch off the exceptions is STL?

注意:在我的代码中我想关闭RTTI选项。

Note: In my code I want to switch off the RTTI options, too. I get the same warnings no matter if the RTTI is on or off.

推荐答案

Microsoft STL支持异常停用。

Microsoft STL supports exception deactivation.

对于MSVC STL定义宏_HAS_EXCEPTIONS = 0,如果您将应用程序与libcmt.lib / libcmtd.lib(/ MT或/ MTd编译器选项)链接,将禁用异常。

For MSVC STL defining macro _HAS_EXCEPTIONS=0 disables exceptions in case you link your application with libcmt.lib/libcmtd.lib (/MT or /MTd compiler option).

如果你链接到msvcrt.lib / msvcrtd.lib(/ MD或/ MDd编译器选项),你需要再定义一个宏_STATIC_CPPLIB。在这种情况下,在包含任何STL代码之前添加以下行:

If you link with msvcrt.lib/msvcrtd.lib (/MD or /MDd compiler option) you need to define one more macro - _STATIC_CPPLIB. In this case either add the following lines before including any STL code:

#define _HAS_EXCEPTIONS 0
#define _STATIC_CPPLIB

或将以下内容添加到编译器选项中:

or add the following to compiler options:

-D_HAS_EXCEPTIONS=0 -D_STATIC_CPPLIB

请注意,在项目设置中禁用C ++异常。

Please note that you need to disable C++ exceptions in your project settings.

这篇关于我可以在STL中禁用异常吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 20:06