【问题标题】:Boost-log linker errorBoost-log 链接器错误
【发布时间】:2014-01-08 10:30:02
【问题描述】:

我已经从源代码下载并构建了 Boost 1.55。我正在尝试使用 Boost-log。在基本情况下(http://boost-log.sourceforge.net/libs/log/doc/html)/log/tutorial.html#log.tutorial.trivial 它可以正常工作,没有任何问题,但是当我尝试使用一些更高级的功能(例如 - http://boost-log.sourceforge.net/libs/log/example/doc/tutorial_fmt_stream.cpp)时,我收到了这个错误:

main.obj:错误 LNK2019:无法解析的外部符号“void __cdecl boost::filesystem::path_traits::convert(char const *,char const *,类 std::basic_string,类 std::allocator> &,class std::codecvt const &)" (?convert@path_traits@filesystem@boost@@YAXPBD0AAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@ ABV?$codecvt@GDH@5@@Z) 在函数“void __cdecl”中引用 boost::filesystem::path_traits::dispatch,class std::allocator > >(class std::basic_string,类 std::allocator > const &,class std::basic_string,class std::allocator > &,class std::codecvt const &)" (??$dispatch@V?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@std@@@path_traits@filesystem@boost@@YAXABV?$basic_string@DU?$ char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$basic_string@GU?$char_traits@G@std@@V?$allocator@G@2@@4@ABV?$ codecvt@GDH@4@@Z)

1>main.obj:错误 LNK2019:无法解析的外部符号“void __cdecl boost::log::v2s_mt_nt5::aux::code_convert(unsigned short const *,unsigned int,class std::basic_string,class std::allocator > &,class std::locale 常量 &)" (?code_convert@aux@v2s_mt_nt5@log@boost@@YAXPBGIAAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABVlocale@6@@Z) 在函数“private: void __thiscall”中引用 boost::log::v2s_mt_nt5::basic_formatting_ostream,类 std::allocator> ::aligned_write(unsigned short const *,__int64)" (??$aligned_write@G@?$basic_formatting_ostream@DU?$char_traits@D@std@@V?$allocator@D@2@@v2s_mt_nt5@log@boost@ @AAEXPBG_J@Z)

1>main.obj:错误 LNK2019:无法解析的外部符号“public:static 类 std::codecvt const & __cdecl boost::filesystem::path::codecvt(void)" (?codecvt@path@filesystem@boost@@SAABV?$codecvt@GDH@std@@XZ) 在函数“public: __thiscall”中引用 boost::filesystem::path::path(char const (&)[14],void *)" (??$?0$$BY0O@$$CBD@path@filesystem@boost@@QAE@AAY0O@$$CBDPAX@Z)

所以基本上它在 .lib 文件中找不到函数 convert(...)、code_convert(...) 和 codecvt(...)。

我已经尝试将所有发布库(构建 boost 时生成的 .lib 文件)添加到“其他库”中,通常我认为 Visual Studio 可以找到所有库,但在库中找不到这些函数。有什么想法可以解决这个问题吗?

我使用 Visual Studio 2010 (msvc10.0)、32 位、发布和调试从源代码构建了 Boost 1.55。我正在使用 Windows 7 x64。

【问题讨论】:

  • MSVC 自动链接提升库,因此您不必显式链接它们。然而unsigned short 看起来很可疑。检查您是否使用“/Zc:wchar_t”选项编译所有内容,即“wchar_t Is Native Type”。
  • 您是否在项目中为 boost.log 使用与编译源代码时相同的设置(阅读:#defines)?在我们的例子中,我们必须确保在包括 boost.log 标头在内的项目中使用BOOST_LOG_NO_THREADS,否则我们会得到不同但同样令人讨厌的链接器错误。

标签: c++ visual-studio-2010 boost linker boost-log


【解决方案1】:

我遇到了同样的问题,我可以通过更改 VisualStudio 2010 上的项目属性之一来解决它。

转到:

属性页 -> ConfigurationProperties -> C/C++ -> 语言 -> 将 WChar_t 视为内置类型:

并将属性设置为:

是的 (/Zc:wchar_t)

希望对你也有帮助:)

保重,

【讨论】:

    猜你喜欢
    • 2016-12-20
    • 2021-02-12
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-10
    相关资源
    最近更新 更多