我可以在STL中禁用异常吗? [英] Can I disable exceptions in STL?

查看:148
本文介绍了我可以在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块,但是我使用STL。我发现使用宏定义_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-interface类的基础'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中禁用异常吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆