Visual 2015链接错误与boost日志

Visual 2015 link error with boost log

本文关键字:boost 日志 错误 2015 链接 Visual      更新时间:2023-10-16

我正在研究从VS'2008+Boost 1.144到VS'2015+Boost 1.61的源代码迁移,我得到了以下链接错误

... error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl boost::log::v2_mt_nt5::attributes::named_scope::push_scope(struct boost::log::v2_mt_nt5::attributes::named_scope_entry const &)" (__imp_?push_scope@named_scope@attributes@v2_mt_nt5@log@boost@@SAXABUnamed_scope_entry@2345@@Z) referenced in function "public: __thiscall boost::log::v2_mt_nt5::attributes::named_scope::sentry::sentry(class boost::log::v2_mt_nt5::basic_string_literal<char,struct std::char_traits<char> > const &,class boost::log::v2_mt_nt5::basic_string_literal<char,struct std::char_traits<char> > const &,unsigned int,enum boost::log::v2_mt_nt5::attributes::named_scope_entry::scope_name_type)" (??0sentry@named_scope@attributes@v2_mt_nt5@log@boost@@QAE@ABV?$basic_string_literal@DU?$char_traits@D@std@@@345@0IW4scope_name_type@named_scope_entry@2345@@Z)
... : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl boost::log::v2_mt_nt5::attributes::named_scope::pop_scope(void)" (__imp_?pop_scope@named_scope@attributes@v2_mt_nt5@log@boost@@SAXXZ) referenced in function "public: __thiscall boost::log::v2_mt_nt5::attributes::named_scope::sentry::~sentry(void)" (??1sentry@named_scope@attributes@v2_mt_nt5@log@boost@@QAE@XZ)

我使用:

bootstrap.bat
b2 --build-dir=build-directory toolset=msvc-14.0 --build-type=complete define=BOOST_LOG_NO_COMPILER_TLS stage

在源代码中,我使用BOOST_LOG_DYN_LINK。似乎我使用的所有其他boost库都被找到并正确链接,但不是boost日志,只有这两个函数。

我注意到在boost/log/attributes/named_scoped.hpp中,这两个函数被定义为named_scope类的static member(见下文)。我想知道这是不是联动问题的原因?因为我不确定静态函数可以从dll导出/加载!

 /*!
     * The method pushes the scope to the back of the current thread's scope list
     *
     * b Throws: Nothing.
     */
    static void push_scope(scope_entry const& entry) BOOST_NOEXCEPT;
    /*!
     * The method pops the last pushed scope from the current thread's scope list
     *
     * b Throws: Nothing.
     */
    static void pop_scope() BOOST_NOEXCEPT;

我怀疑你的代码和Boost.Log之间的目标Windows API版本不匹配。