使用init_from_source时的Boost.Log链接器错误

时间:2019-02-25 11:03:30

标签: c++ logging boost

我正在Windows上编写一个程序,该程序使用Boost库进行记录。但是,当我想使用功能 init_from_source 初始化记录器时,出现以下错误:

libboost_log_setup-vc141-mt-gd-x64-1_69.lib(matches_relation_factory.obj) : error LNK2019: unresolved external symbol "private: class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > & __cdecl boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::do_assign(char const *,char const *,unsigned int)" (?do_assign@?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@boost@@AEAAAEAV12@PEBD0I@Z) referenced in function "public: class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > & __cdecl boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::assign(char const *,char const *,unsigned int)" (?assign@?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@boost@@QEAAAEAV12@PEBD0I@Z)
libboost_log_setup-vc141-mt-gd-x64-1_69.lib(matches_relation_factory.obj) : error LNK2019: unresolved external symbol "public: bool __cdecl boost::re_detail_106900::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::match(void)" (?match@?$perl_matcher@PEBDV?$allocator@U?$sub_match@PEBD@boost@@@std@@U?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@re_detail_106900@boost@@QEAA_NXZ) referenced in function "bool __cdecl boost::regex_match<char const *,class std::allocator<struct boost::sub_match<char const *> >,char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >(char const *,char const *,class boost::match_results<char const *,class std::allocator<struct boost::sub_match<char const *> > > &,class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags)" (??$regex_match@PEBDV?$allocator@U?$sub_match@PEBD@boost@@@std@@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@boost@@YA_NPEBD0AEAV?$match_results@PEBDV?$allocator@U?$sub_match@PEBD@boost@@@std@@@0@AEBV?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@0@W4_match_flags@regex_constants@0@@Z)
libboost_log_setup-vc141-mt-gd-x64-1_69.lib(matches_relation_factory.obj) : error LNK2019: unresolved external symbol "private: void __cdecl boost::re_detail_106900::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::construct_init(class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags)" (?construct_init@?$perl_matcher@PEBDV?$allocator@U?$sub_match@PEBD@boost@@@std@@U?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@re_detail_106900@boost@@AEAAXAEBV?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@3@W4_match_flags@regex_constants@3@@Z) referenced in function "public: __cdecl boost::re_detail_106900::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::perl_matcher<char const *,class std::allocator<struct boost::sub_match<char const *> >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >(char const *,char const *,class boost::match_results<char const *,class std::allocator<struct boost::sub_match<char const *> > > &,class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > const &,enum boost::regex_constants::_match_flags,char const *)" (??0?$perl_matcher@PEBDV?$allocator@U?$sub_match@PEBD@boost@@@std@@U?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@re_detail_106900@boost@@QEAA@PEBD0AEAV?$match_results@PEBDV?$allocator@U?$sub_match@PEBD@boost@@@std@@@2@AEBV?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@2@W4_match_flags@regex_constants@2@0@Z)
libboost_log_setup-vc141-mt-gd-x64-1_69.lib(matches_relation_factory.obj) : error LNK2019: unresolved external symbol "private: class boost::basic_regex<wchar_t,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > > & __cdecl boost::basic_regex<wchar_t,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > >::do_assign(wchar_t const *,wchar_t const *,unsigned int)" (?do_assign@?$basic_regex@_WU?$regex_traits@_WV?$w32_regex_traits@_W@boost@@@boost@@@boost@@AEAAAEAV12@PEB_W0I@Z) referenced in function "public: class boost::basic_regex<wchar_t,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > > & __cdecl boost::basic_regex<wchar_t,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > >::assign(wchar_t const *,wchar_t const *,unsigned int)" (?assign@?$basic_regex@_WU?$regex_traits@_WV?$w32_regex_traits@_W@boost@@@boost@@@boost@@QEAAAEAV12@PEB_W0I@Z)
libboost_log_setup-vc141-mt-gd-x64-1_69.lib(matches_relation_factory.obj) : error LNK2019: unresolved external symbol "public: bool __cdecl boost::re_detail_106900::perl_matcher<wchar_t const *,class std::allocator<struct boost::sub_match<wchar_t const *> >,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > >::match(void)" (?match@?$perl_matcher@PEB_WV?$allocator@U?$sub_match@PEB_W@boost@@@std@@U?$regex_traits@_WV?$w32_regex_traits@_W@boost@@@boost@@@re_detail_106900@boost@@QEAA_NXZ) referenced in function "bool __cdecl boost::regex_match<wchar_t const *,class std::allocator<struct boost::sub_match<wchar_t const *> >,wchar_t,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > >(wchar_t const *,wchar_t const *,class boost::match_results<wchar_t const *,class std::allocator<struct boost::sub_match<wchar_t const *> > > &,class boost::basic_regex<wchar_t,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > > const &,enum boost::regex_constants::_match_flags)" (??$regex_match@PEB_WV?$allocator@U?$sub_match@PEB_W@boost@@@std@@_WU?$regex_traits@_WV?$w32_regex_traits@_W@boost@@@boost@@@boost@@YA_NPEB_W0AEAV?$match_results@PEB_WV?$allocator@U?$sub_match@PEB_W@boost@@@std@@@0@AEBV?$basic_regex@_WU?$regex_traits@_WV?$w32_regex_traits@_W@boost@@@boost@@@0@W4_match_flags@regex_constants@0@@Z)
libboost_log_setup-vc141-mt-gd-x64-1_69.lib(matches_relation_factory.obj) : error LNK2019: unresolved external symbol "private: void __cdecl boost::re_detail_106900::perl_matcher<wchar_t const *,class std::allocator<struct boost::sub_match<wchar_t const *> >,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > >::construct_init(class boost::basic_regex<wchar_t,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > > const &,enum boost::regex_constants::_match_flags)" (?construct_init@?$perl_matcher@PEB_WV?$allocator@U?$sub_match@PEB_W@boost@@@std@@U?$regex_traits@_WV?$w32_regex_traits@_W@boost@@@boost@@@re_detail_106900@boost@@AEAAXAEBV?$basic_regex@_WU?$regex_traits@_WV?$w32_regex_traits@_W@boost@@@boost@@@3@W4_match_flags@regex_constants@3@@Z) referenced in function "public: __cdecl boost::re_detail_106900::perl_matcher<wchar_t const *,class std::allocator<struct boost::sub_match<wchar_t const *> >,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > >::perl_matcher<wchar_t const *,class std::allocator<struct boost::sub_match<wchar_t const *> >,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > >(wchar_t const *,wchar_t const *,class boost::match_results<wchar_t const *,class std::allocator<struct boost::sub_match<wchar_t const *> > > &,class boost::basic_regex<wchar_t,struct boost::regex_traits<wchar_t,class boost::w32_regex_traits<wchar_t> > > const &,enum boost::regex_constants::_match_flags,wchar_t const *)" (??0?$perl_matcher@PEB_WV?$allocator@U?$sub_match@PEB_W@boost@@@std@@U?$regex_traits@_WV?$w32_regex_traits@_W@boost@@@boost@@@re_detail_106900@boost@@QEAA@PEB_W0AEAV?$match_results@PEB_WV?$allocator@U?$sub_match@PEB_W@boost@@@std@@@2@AEBV?$basic_regex@_WU?$regex_traits@_WV?$w32_regex_traits@_W@boost@@@boost@@@2@W4_match_flags@regex_constants@2@0@Z)
fatal error LNK1120: 6 unresolved externals


我正在像这样构建Boost:

b2 -j8 toolset=msvc-14.1 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=complete stage
b2 -j8 toolset=msvc-14.1 address-model=64 architecture=x86 link=shared threading=multi runtime-link=shared --with-thread --build-type=minimal stage


我可以看到 init_from_source 已构建:

compile-c-c++ bin.v2\libs\log\build\msvc-14.1\debug\address-model-64\threadapi-win32\threading-multi\setup\init_from_stream.obj
init_from_stream.cpp

compile-c-c++ bin.v2\libs\log\build\msvc-14.1\release\address-model-64\threadapi-win32\threading-multi\setup\init_from_stream.obj
init_from_stream.cpp

我正在Visual Studio中链接它。


如果删除函数init_from_stream,则代码编译不会有任何问题。另外,我已经使用Boost读取配置文件和内存映射,并且效果很好。


由于它不适用于我的项目,因此我尝试进行另一项测试。我创建了一个新项目,将Boost链接到该项目,并尝试运行以下代码:

#include <fstream>
#include <boost/log/utility/setup/from_stream.hpp>


int main() {
    std::fstream fs{ "settings.ini" };
    boost::log::init_from_stream(fs);

    return 0;
}

同样,会发生同样的问题。


如果我尝试进行动态构建,这是我得到的错误:

Source.obj : error LNK2019: unresolved external symbol "void __cdecl boost::log::v2_mt_nt6::init_from_stream<char>(class std::basic_istream<char,struct std::char_traits<char> > &)" (??$init_from_stream@D@v2_mt_nt6@log@boost@@YAXAEAV?$basic_istream@DU?$char_traits@D@std@@@std@@@Z) referenced in function main


有人知道我想念什么吗?


更新

当我试图动态链接库时,我在包含之前使用了#define BOOST_LOG_DYN_LINK


我也尝试了这些链接中的解决方案,但没有帮助:

Boost-log linker error

Fatal error LNK1104: cannot open file 'libboost_log-vc141-mt-gd-1_64.lib'


更新

boost_1_69_0 / stage / lib目录中同时存在libboost_regex-vc141-mt-gd-x64-1_69.liblibboost_log-vc141-mt-x64-1_69.lib

1 个答案:

答案 0 :(得分:0)

缺少的符号来自Boost.Regex,Boost.Log使用它(更确切地说,boost_log_setup在内部引用其符号)。您需要将Boost.Regex添加到要链接的库列表中。给定您的错误消息,对于您的静态链接版本,应该为libboost_regex-vc141-mt-gd-x64-1_69.lib