我正在使用Visual C++ 2005速成版,并收到以下链接器错误:
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)我在生成的代码中关闭了异常,并在包含向量头文件之前使用:
#define _HAS_EXCEPTIONS 0几个谷歌搜索结果显示了一些东西,但没有“啊哈!”对我有效的解决方案。
编辑:
正如前面提到的,"_HAS_EXCEPTIONS 0“本身并不会关闭异常。它所做的是,至少在向量头文件中,是在异常对象上调用_Raise,而不是调用C++“抛出”。在我的例子中,它不能链接到异常对象的_Raise函数,因为我没有包含正确的库。然而,这个库是什么并不明显。
发布于 2008-10-31 16:15:35
添加此行:
#define _STATIC_CPPLIB在包含向量头之前似乎可以做到这一点。
发布于 2008-10-30 09:45:00
第三个错误清楚地表明#define the _HAS_EXCEPTIONS 0不会影响。现在,可能包含(有道理,共享代码可能会减少可执行文件的大小)。这就解释了为什么在包含之前定义它仍然会有错误。这种定义应该在您的项目设置中完成。
请注意,_HAS_EXCEPTIONS在Visual Studio中是一个不受支持的功能。它本身并不会关闭异常。
https://stackoverflow.com/questions/249607
复制相似问题