7
votes

I am having problems linking Boost Regex, though I can run (compile/link) other Boost Programs.

I realise that this is "well documented" but I cannot find the answer as the various posts use different versions of Boost, different compilers, use bjam (I used b2), seem to suggest what I have already tried etc.

The Setup

  • Visual Studio 10 (I am using C++)

  • Boost Version: 1.53.0

  • Initial Install: I followed How to use Boost in Visual Studio 2010 (I went as far as the second point 4). I have not downloaded the ICU support for Regex as I think this is only required if you need Unicode support?

  • I have included the relevant library in the Project Properties by updating "Include Directories" and adding C:.......\Boost\boost_1_53_0

  • I have included the relevant directory in the Project Properties Library Directories by adding "C:.....\Boost\boost_1_53_0\stage\lib" so that it knows where the libraries are to link from (at least that is what I think this does).

The Problem

I can compile, link and run a program using (for example) Boost Random Numbers.

If I tried to add Regex functionality by saying:

boost::algorithm::split_regex( result, str, regex( "[0-9]+|->" ) )

I get linking errors of the following form.

1>Bibtex.obj : error LNK2001: unresolved external symbol "private: class boost::basic_regex<char,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > > & __thiscall 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@@AAEAAV12@PBD0I@Z)
1>Bibtex.obj : error LNK2001: unresolved external symbol "public: bool __thiscall boost::re_detail::perl_matcher<class std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<struct boost::sub_match<class std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> > > >,struct boost::regex_traits<char,class boost::w32_regex_traits<char> > >::find(void)" (?find@?$perl_matcher@V?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@U?$sub_match@V?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@boost@@@2@U?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@re_detail@boost@@QAE_NXZ)
1>Bibtex.obj : error LNK2001: unresolved external symbol "private: void __thiscall boost::re_detail::perl_matcher<class std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<struct boost::sub_match<class std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> > > >,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@V?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@U?$sub_match@V?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@boost@@@2@U?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@re_detail@boost@@AAEXABV?$basic_regex@DU?$regex_traits@DV?$w32_regex_traits@D@boost@@@boost@@@3@W4_match_flags@regex_constants@3@@Z)
1>C:\Users\kzzgrk\Dropbox\Projects\classes\Bibtex\BibtexFramework\Debug\BibtexFramework.exe : fatal error LNK1120: 3 unresolved externals

I have no idea how to solve this as I seem to have tried everything. The only possibility I can think of is that I need to build the boost libraries using the b2 command line program, but I cannot find out what that commend should be (as I say above a lot of references are to bjam).

Any help/suggestion would be greatly appreciated.

2
Did you actually compile the Boost libraries? Specifically, does the stage\lib directoy contain a libboost_regex.lib file (or similar name)?TemplateRex
Looking at the stage\lib directory. It contains the following files (related to regex) - boost_regex-vc100-mt-1_53.dll, boost_regex-vc100-mt-1_53.bib, boost_regex-vc100-mt-gd-1_53.dll, boost_regex-vc100-mt-gd-1_53.bibGraham
Did you #include the boost regex header file ? Also, by default, boost auto-links the correct lib. You can explicitly link a certain lib, but you have to set a #Define such as no auto link boost.user557597
Did you also include the random library by going to Linker->Input and adding it to "Additional Dependencies"? It's not enough to just add the library directory.jhauris
I have exactly the same problem, no idea what's going on here.Dmitri Nesteruk

2 Answers

2
votes

I have discovered one possible cause for this, which could help some people. Basically, I've had Boost built for 64-bit but by default the app I created was 32-bit. This works for most libs but didn't work for the Regex lib, thus the error. Switched project to 64-bit and all is fine now.

0
votes

I have experienced the same problem and fixed it.This kind of errors is mainly caused by the function you declare in the XX.h file but do not define it in the XX.cpp file(or the XX.cpp file is useless)

my steps: 1.download boost

2.run the command in the boost dirctory(you need to generate bjam.exe first,the argument should be according to your PC) bjam --with-regex --toolset=msvc-8.0 --stagedir="E:\download\boost_vc_80" link=static runtime-link=static runtime-link=shared threading=multi debug release

3.copy libboost_regex-vc80-mt-1_55.lib to properties->link->input

build your project again,fixed!

[email protected]