user388225
user388225

Reputation:

boost's regex won't compile

I am using boost 1.45.0 on Ubuntu with Code::Blocks as my IDE, and I can't get basic_regex.hpp to compile. I'm pretty sure I set up boost correctly, because I can compile programs using boost::format without any errors. But I'm getting this annoying error, and I don't know how to get rid of it.

The code that is provoking the error:

boost::regex e("\"http:\\\\/\\\\/localhostr.com\\\\/files\\\\/.+?\"");

Compiler output (GCC):

obj/Debug/main.o
In function `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)'

/home/neal/Documents/boost_1_45_0/boost/regex/v4/basic_regex.hpp|379|
undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'|

||=== Build finished: 1 errors, 0 warnings ===|

Did I miss a step when setting up boost, or should I downgrade to another version of boost?

Upvotes: 6

Views: 8084

Answers (3)

chrisaycock
chrisaycock

Reputation: 37930

That's a linking error rather than a compiler error. You need to explicitly link against Boost's regex library.

g++ program.cpp -lboost_regex -L/path/to/boost/lib

Upvotes: 2

SoapBox
SoapBox

Reputation: 20609

Boost::Regex has some code that lives in a separate library (libboost_regex.so). To link against it, add -lboost_regex to the GCC commandline you're using.

Depending on your install, that might be libboost_regex-mt.so. In that case, you'll need to use -lboost_regex-mt on your command line. (The MT stands for mutlithreaded.)

Upvotes: 9

Vikas
Vikas

Reputation: 8948

This looks like a linker error. boost::regex is not a header only library so you need to pass -lboost_regex with correct -L/path/to/boost/lib to linker.

Upvotes: 12

Related Questions