Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
146 views
in Technique[技术] by (71.8m points)

c++ - Can I disable exceptions in STL?

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.


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:


warning C4275: non dll-interface class 'stdext::exception' used as base for dll-interface class 'std::bad_typeid' see declaration of 'stdext::exception' see declaration of 'std::bad_typeid'


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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Microsoft STL supports exception deactivation.

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).

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...