Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  • 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.

like image 859
Graham Avatar asked Apr 14 '13 09:04

Graham


People also ask

How do I add a boost library?

Go to Project properties → C/C++ → General → Additional Include Directories, and add a path to the boost library root (in my case C:\Program Files (x86)\Boost_1_53 ). Include a . hpp file in your sources, like #include <boost/lexical_cast/lexical_cast_old. hpp>

How do I link my boost library to Visual Studio?

6.1 Link From Within the Visual Studio IDE Right-click example in the Solution Explorer pane and select Properties from the resulting pop-up menu. In Configuration Properties > Linker > Additional Library Directories, enter the path to the Boost binaries, e.g. C:\Program Files\boost\boost_1_55_0\lib\.

Is boost library header only?

Most Boost libraries are header-only: they consist entirely of header files containing templates and inline functions, and require no separately-compiled library binaries or special treatment when linking. The only Boost libraries that must be built separately are: Boost.

What is boost regex?

Boost. Regex allows you to use regular expressions in C++. As the library is part of the standard library since C++11, you don't depend on Boost. Regex if your development environment supports C++11. You can use identically named classes and functions in the namespace std if you include the header file regex .


1 Answers

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.

like image 110
Dmitri Nesteruk Avatar answered Sep 17 '22 23:09

Dmitri Nesteruk