c++ - 使用 init_from_source 时的 Boost.Log 链接器错误
问题描述
我正在 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
在包含之前使用
我也尝试了这些链接中的解决方案,但没有帮助:
致命错误 LNK1104:无法打开文件“libboost_log-vc141-mt-gd-1_64.lib”
更新
boost_1_69_0/stage/lib 目录下都有libboost_regex-vc141-mt-gd-x64-1_69.lib
和libboost_log-vc141-mt-x64-1_69.lib
解决方案
缺少的符号来自 Boost.Regex,Boost.Log 使用它(更准确地说,boost_log_setup
在内部引用它的符号)。您需要将 Boost.Regex 添加到要链接的库列表中。鉴于您的错误消息,这应该libboost_regex-vc141-mt-gd-x64-1_69.lib
用于您的静态链接构建。
推荐阅读
- angular6 - ReferenceError:$ 未在 Angular 中定义
- javascript - 两张幻灯片无法同时播放
- mailchimp-api-v3.0 - MailChimp 重新订阅已删除的成员会导致 API 返回 400 错误请求
- reactjs - 当 api 不返回图像 url 时使用 React 进行条件渲染
- java - 保存的位图方向不正确
- javascript - 如何在d3 v4中垂直添加交错色带
- kotlin - Replace () -> Unit 为简单的 RxJava 解决方案
- c# - 在 Plesk 中禁止使用 Asp.Net MVC
- blockchain - 如何在 Namecoin 区块链或任何基于身份的区块链(如 Emercoin)上存储和查询数据
- reactjs - React 模型打开时滚动到底部