views:

1496

answers:

2

I am using Visual C++ 2005 Express Edition and get the following linker errors:

19>mylib1.lib(mylibsource1.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<class mytype,class std::allocator<class mytype> >::_Xlen(void)" (?_Xlen@?$vector@Vmytype@@V?$allocator@Vmytype@@@std@@@std@@KAXXZ)
19>mylib2.lib(mylibsource2.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " (__imp_?_Raise@exception@std@@QBEXXZ)
19>mylib1.lib(mylibsource1.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)
19>mylib2.lib(mylibsource2.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::exception::exception(char const *,int)" (__imp_??0exception@std@@QAE@PBDH@Z)

I turned off exceptions in generated code, and I am using before including the vector header file:

#define _HAS_EXCEPTIONS 0

A few Google results turned up some stuff, but no "aha!" solutions that worked for me.

EDIT:

As noted "_HAS_EXCEPTIONS 0" doesn't turn off exceptions, per se. What it does is, at least in the vector header file, is call _Raise on an exception object instead of calling the C++ "throw". In my case, it can't link to the exception object's _Raise function since I am not including the correct library. What that library is, though, is not obvious.

A: 

The third error makes it clear that #define the _HAS_EXCEPTIONS 0 does not affect . Now, might include (makes sense, sharing code might reduce the size of your executable). That would explain why you still have errors if you define it before your inclusion of . This kind of defines should be done in your project settings.

Note that _HAS_EXCEPTIONS is an unsupported feature in Visual Studio. It does not turn off exceptions as such.

MSalters
+1  A: 

Adding this line:

#define _STATIC_CPPLIB

before including the vector header seems to do the trick.

Jim Buck