2008-10-30 30 views
0

我使用Visual C++ 2005 Express版本,并得到下面的连接错误:VC++上的std ::例外链接错误:: _加薪和std ::例外::例外

19>mylib1.lib(mylibsource1.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " ([email protected]@[email protected]@QBEXXZ) referenced in function "protected: static void __cdecl std::vector<class mytype,class std::allocator<class mytype> >::_Xlen(void)" ([email protected][email protected]@@[email protected]@@@[email protected]@@[email protected]@KAXXZ) 
19>mylib2.lib(mylibsource2.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " ([email protected]@[email protected]@QBEXXZ) 
19>mylib1.lib(mylibsource1.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::exception::exception(char const *,int)" ([email protected]@@[email protected]@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 &)" ([email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) 
19>mylib2.lib(mylibsource2.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::exception::exception(char const *,int)" ([email protected]@@[email protected]@Z) 

我关掉例外产生代码,我使用包括矢量头文件之前:

#define _HAS_EXCEPTIONS 0 

一些谷歌搜索结果打开了一些东西,但没有“啊哈!”为我工作的解决方案。

编辑:

正如所指出的 “_HAS_EXCEPTIONS 0” 不会关闭异常,本身。它至少在矢量头文件中所做的是在异常对象上调用_Raise,而不是调用C++“throw”。在我的情况下,它不能链接到异常对象的_Raise函数,因为我没有包含正确的库。但是,该图书馆的内容并不明显。

回答

1

添加此行:

#define _STATIC_CPPLIB 

包括矢量头文件之前,似乎这样的伎俩。

0

第三个错误表明#define the _HAS_EXCEPTIONS 0不会影响。现在,可能包括(有意义的是,共享代码可能会减少可执行文件的大小)。这可以解释为什么如果你在之前定义它,你仍然会有错误,包括你的。这种定义应该在您的项目设置中完成。

请注意,_HAS_EXCEPTIONS是Visual Studio中不受支持的功能。它不会像这样关闭例外。