2008-10-30 78 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中不受支持的功能。它不會像這樣關閉例外。