代码之家  ›  专栏  ›  技术社区  ›  Jim Buck

在std::exception::_raise和std::exception::exception上发生VC++链接器错误

  •  0
  • Jim Buck  · 技术社区  · 17 年前

    我使用Visual C++ 2005 Express版并获得以下链接器错误:

    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
    

    一些谷歌搜索结果显示了一些东西,但没有“啊哈!”对我有用的解决方案。

    编辑:

    如前所述,“有异常0”本身不会关闭异常。它所做的至少在向量头文件中是一个异常对象的调用上调,而不是调用C++“抛出”。在我的例子中,它不能链接到异常对象的raise函数,因为我没有包含正确的库。不过,那个图书馆是什么并不明显。

    2 回复  |  直到 10 年前
        1
  •  1
  •   Jim Buck    17 年前

    添加此行:

    #define _STATIC_CPPLIB
    

    在包含向量头之前,似乎可以做到这一点。

        2
  •  0
  •   MSalters    17 年前

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

    请注意,在Visual Studio中,has-has-exceptions是不受支持的功能。它不会像这样关闭异常。