0

I'm writing a program on Windows that uses Boost library for logging. However, when I want to initialize a logger using the function init_from_source, I get these errors:

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


I'm building Boost like this:

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


I can see that init_from_source gets built:

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

And I'm linking it in Visual Studio.


If I remove the function init_from_stream, the code compiles without any issues. Also, I've used Boost for reading config files and memory mapping, and it worked just fine.


Since it doesn't work on my project, I tried to make another test. I created a new project, linked Boost to it, and tried to run this code:

#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;
}

Again, the same issue occurs.


If I try to build it dinamically, this is the error that I get:

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


Anyone knows what I'm missing?


UPDATE

When I tried to dinamically link the library, I used #define BOOST_LOG_DYN_LINK before the includes


I tried the solutions from these links also, but it didn't help:

Boost-log linker error

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


UPDATE

There are both libboost_regex-vc141-mt-gd-x64-1_69.lib and libboost_log-vc141-mt-x64-1_69.lib in the boost_1_69_0/stage/lib directory

Maki
  • 177
  • 7
  • Check *all* answers of the duplicate, you might need multiple solutions. – Some programmer dude Feb 25 '19 at 11:06
  • Not sure why is it marked as duplicate? I checked other answers on stackoverflow, but they didn't work for me. – Maki Feb 25 '19 at 11:10
  • So neither defining the macro `BOOST_LOG_DYN_LINK` *at the right place*, nor linking with `boost_log_setup` worked? Then you should have *told* us. You need to tell us *exactly* what you have tried, and if solutions from other questions and answers you could add links to those so we know *exactly* what you have tried. Also please take some time to read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). – Some programmer dude Feb 25 '19 at 11:12
  • Thanks for the feedback, I'll update the question right now! – Maki Feb 25 '19 at 12:13

1 Answers1

0

The missing symbols are from Boost.Regex, which is used by Boost.Log (more precisely, boost_log_setup references its symbols internally). You need to add Boost.Regex to the list of the libraries to link with. Given your error messages, that should be libboost_regex-vc141-mt-gd-x64-1_69.lib for your static linking build.

Andrey Semashev
  • 10,046
  • 1
  • 17
  • 27
  • I'll update my question again. It has both **libboost_regex-vc141-mt-gd-x64-1_69.lib** and **libboost_log-vc141-mt-gd-x64-1_69.lib** in the lib directory – Maki Feb 26 '19 at 13:21
  • It's not about what you have in your lib directory, it's about what libraries you link with. – Andrey Semashev Feb 26 '19 at 15:36
  • Sorry, but I'm completely new to Boost. I'm linking boost in Visual Studio, and I followed the example on the official boost website [link program to boost library within the visual studio ide](https://www.boost.org/doc/libs/1_69_0/more/getting_started/windows.html#link-from-within-the-visual-studio-ide). I might be missing something, but I think that regex should be already linked this way? – Maki Feb 26 '19 at 17:46
  • No. Additional Library Directories lists the directories where libraries will be looked for. The actual libraries that are linked are either specified explicitly (there is a separate field for that in Visual Studio, in the linker settings) or are pulled automatically via `#pragma`s in the headers you include (so-called autolinking). However, autolinking doesn't work if a library is pulled indirectly through another static library, which is the case with Boost.Regex and Boost.Log. – Andrey Semashev Feb 27 '19 at 09:02
  • Thank you, it finally works! I didn't know that I need to add the .lib files to the "Additional Dependencies" field. I found it weird that nobody's mentioning it, but everything else that I used worked without modifying that field, so I just assumed that that's not the issue. – Maki Feb 27 '19 at 12:00