Graham
Graham

Reputation: 129

Boost Regex Linking: Can't find library

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

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.

Upvotes: 7

Views: 4284

Answers (2)

Trainy
Trainy

Reputation: 26

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]

Upvotes: 0

Dmitri Nesteruk
Dmitri Nesteruk

Reputation: 23789

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.

Upvotes: 2

Related Questions