使用init_from_source时,boost.log链接器错误
Boost.Log linker error when using init_from_source
我在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
我正在建立这样的提升:
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.v2libslogbuildmsvc-14.1debugaddress-model-64threadapi-win32threading-multisetupinit_from_stream.obj
init_from_stream.cpp
compile-c-c++ bin.v2libslogbuildmsvc-14.1releaseaddress-model-64threadapi-win32threading-multisetupinit_from_stream.obj
init_from_stream.cpp
我正在链接在Visual Studio中。
如果我删除函数init_from_stream,则无问题编译代码。另外,我已经使用了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
有人知道我缺少什么吗?
update
当我尝试将图书馆链接起来时,我在包含
之前使用了#define BOOST_LOG_DYN_LINK
我也尝试了这些链接的解决方案,但这无济于事:
Boost-Log链接器错误
致命错误lnk1104:无法打开文件'libboost_log-vc141-mt-gd-1_64.lib'
update
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
。
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- CMake-按正确顺序将项目与C运行时对象文件链接
- 从链接列表c++中删除一个项目
- 有根的二进制搜索树.保留与其父级的链接
- 读取文件的最后一行并输入到链接列表时出错
- 静态数据成员的问题-修复链接错误会导致编译器错误
- node-gyp 在 macOS 上未正确链接库
- 基于boost的程序的静态链接——zlib问题
- 无法链接 CMake 中的本地库
- 内联函数中具有内部链接的全局变量
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 使用gcc从静态链接的文件中查找可选符号
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- 使用init_from_source时,boost.log链接器错误
- 为什么将链接限制与boost :: log
- 由于缺少code_convert,Boost.Log 无法与静态库链接
- 尝试构建Boost.Log示例时发生链接错误
- 在OS X 10.7上使用MacPorts时出现Boost.Log链接错误
- 为什么Android NDK log.h __android_log_print链接错误
- Visual Studio 2013 Boost-log v1_61_0链接错误