Boost (Regex) Linker problem

Hello all,

Ive been searching for a good while now and have an idea of what is happening back stage yet cant find a way to fix it.

Trying to use regular expressions to find tags in a string:
[Event "Event1"]
[Round "1"]

I include boost/regex.hpp like in every example I found:
#include <boost/regex.hpp>
and as soon as I do:
const boost::regex e("[a-z]+");
( Thats my last copy paste to make sure it wasnt a faulty expression )
my regular expression looks like this:
std::string sRegex("^" +sTag + "[[:space:]]\"(.*)\"$");
where sTag is a function param.

When I try to compile I get the following error:

build/Debug/GNU-Linux-x86/Analyzer.o: In function `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)':
/usr/include/boost/regex/v4/basic_regex.hpp:273: undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'
collect2: ld returned 1 exit status


I got Boost from the Ubuntu repositories (Synaptic) and didnt get any error or message to notice. Im using Netbeans 6.8 with g++
if I comment that line out (where the regex is declared) program compiles fine.

Anyone ran into this or know how to fix?
How are you compiling? Did you tell the linker that you are using the library?
Have a quick look at this related thread (and the thread related to it, if necessary):
http://www.cplusplus.com/forum/general/20194/
In Netbeans, try right clicking on the project and going to Properties (if I remember correctly). Somewhere in there you'll be able to specify include paths, library paths, libraries, etc.. I think you'll have to link with the boost_regex library.
Thank you for your suggestions, finally figured it out (I think)

here's what I've done (maybe someone will find it helpful in the future)
- On Project properties went to the Linker section and added /usr/include/boost;/usr/include/boost/regex (find tells me thats where regex.hpp is), tried to compile again and same problem.
- Additional to above (not undoing it), went to Project properties -> C++ Compiler -> Add Library, added /usr/include/boost;/usr/include/boost/regex, still nothing.
- Additional to above (also not undoing) tried adding -lboost_regex to the linker (project properties) and got a different error:

g++ -lboost_regex -o dist/Debug/GNU-Linux-x86/chessparser01 build/Debug/GNU-Linux-x86/Board.o build/Debug/GNU-Linux-x86/Director.o build/Debug/GNU-Linux-x86/Analyzer.o build/Debug/GNU-Linux-x86/main.o -L/usr/include/boost -L/usr/include/boost/regex
/usr/bin/ld: cannot find -lboost_regex

so I issued a find: find /usr/lib -name libboost\*.so
and found one related to regex:

/usr/lib/libboost_regex-mt.so

So went to the Linker properties once again and Add Library, looked for the exact file but it couldnt find it, instead there was a:
/usr/lib/libboost_regex-mt.a
added that and it compiled, Yay! havent tested it running the full code to search for a match but at least it compiles now.

Thank you very much both of you, have a great weeked!
Topic archived. No new replies allowed.