【发布时间】:2016-08-30 11:58:10
【问题描述】:
我正在将源代码从 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 lib 都已找到并正确链接,但没有 boost log,只有这两个函数。
我注意到在boost/log/attributes/named_scoped.hpp 中,这两个函数被定义为static member 的named_scopeclass(见下文)。我想知道这是否可能是该链接问题的原因?因为我不确定是否可以从 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;
欢迎任何解决该问题的想法或建议。
【问题讨论】:
-
你能仔细检查你在 VS 中链接的库吗?我发现 Boost 的自动链接很棘手。此外,看起来 BOOST_LOG_USE_COMPILER_TLS 可能已经取代了 BOOST_LOG_NO_COMPILER_TLS,但目前还不清楚这是否与问题有关。
-
static成员函数不是问题。
标签: c++ visual-studio-2015 boost-log