VC2005 : Disable c++ exception in Dll application

Hy,
I create a simple Dll application that use stl. I try to disable exception to optimize my application.
First, I disable exception in project properties and I define "#define _HAS_EXCEPTIONS 0
" in my prefix include.

But it doesn't link, I have this error :
error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " (__imp_ _Raise@exception@std@@QBEXXZ) referenced in function "protected: static void __cdecl std::vector<int,class std::allocator<int> >::_Xlen(void)" ( _Xlen@ $vector@HV $allocator@H@std@@@std@@KAXXZ)
1>Exception.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::exception::exception(char const *,int)" (__imp_ 0exception@std@@QAE@PBDH@Z) referenced in function "public: __thiscall std::logic_error::logic_error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ( 0logic_error@std@@QAE@ABV $basic_string@DU $char_traits@D@std@@V $allocator@D@2@@1@@Z)

How to disable exception in stl It's possible to build a Dll application without exception
I tried to replace VC++ stl by stl port, but I won't compile too....

thanks,



Answer this question

VC2005 : Disable c++ exception in Dll application

  • Dean2650

    I made simple Dll projet with VC++ 2005. I include and use vector.
    I change "Enable C++ Exceptions" to "No". I put "/D_HAS_EXCEPTIONS=0" in C++ compiler command line.

    When project link I have these errors:
    ExceptionLink.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " (__imp_ _Raise@exception@std@@QBEXXZ) referenced in function "protected: static void __cdecl std::vector<int,class std::allocator<int> >::_Xlen(void)" ( _Xlen@ $vector@HV $allocator@H@std@@@std@@KAXXZ)
    ExceptionLink.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::exception::exception(char const *,int)" (__imp_ 0exception@std@@QAE@PBDH@Z) referenced in function "public: __thiscall std::logic_error::logic_error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ( 0logic_error@std@@QAE@ABV $basic_string@DU $char_traits@D@std@@V $allocator@D@2@@1@@Z)
    D:\Projets\test\ExceptionLink\Debug\ExceptionLink.dll : fatal error LNK1120: 2 unresolved externals


    You can download my projet here : http://etranges01.free.fr/Exception%20LinkError%20Report.zip

    thanks

  • Looper_Kwok

    That's odd. I made a mock dll project with some assorted STL usage, disabled C++ exceptions in the code generation settings and added the define to the advanced linker cmdline string -- and it worked.

    Could you try making a clean project to test it on



  • porkpiehat

    I try it, but it doesn't change anything.

  • e.henriquez

    This may be an issue addressed by VC8 SP1, as it compiled and linked right out of the box here. See http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=743157&SiteID=1 for download info for the SP1 beta.

  • J. Ho

    Try adding

    /D_HAS_EXCEPTIONS=0

    to the Additional Options setting in the project properties (ALT+F7) -> configuration properties -> c/c++ -> command line page.



  • jordabi

    Maybe you should manipulate the _SECURE_SCL and _SECURE_SCL_THROWS definitions instead See http://msdn2.microsoft.com/en-gb/library/aa985965(VS.80).aspx. I hope that helps.


  • MarkNyats

    It doesn't change anything. I have the same errors.

  • VC2005 : Disable c++ exception in Dll application