Boost :: regex segfaults when using capture

I get a seg error for a simple program below. This seems to be related to the match_results destructor.

#include <iostream> #include <vector> #include <string> #include <boost/regex.hpp> using namespace std; int main(int argc, char *argv) { boost::regex re; boost::cmatch matches; boost::regex_match("abc", matches, re.assign("(a)bc")); return 0; } 

edit: I am using boost 1.39

+4
source share
4 answers

boost :: regex is one of the few boost components that does not exist only in header files ... there is a library module.

The library you are using was probably built with different settings than your application.

Edit: I found an example script with this known boost error where boost should be built with the same -malign-double as your application.

This is one of several possible scenarios in which your boost library will not have binary compatibility with your application.

+4
source

What version of boost are you using?

I have compiled the above example with boost 1.36 and I am not getting any seg errors.

If you have multiple enhancement libraries, make sure you select the correct version at run time.

Boost regex requires compilation in the -lboost_regex-gcc_whatever-is-your- version

In my case:

 g++ -c -Wall -I /include/boost-1_36_0 -o main.o main.cpp g++ -Wall -I /include/boost-1_36_0 -L/lib/boost-1_36_0 -lboost_regex-gcc33-mt main.o -ox 

for execution:

 LD_LIBRARY_PATH=/lib/boost-1_36_0 ./x 

You would indicate the location of boost include / libs in your system, pay attention to the version of gcc and m (ulti) t (hreaded) in the library name - it depends on what you compiled, just look in your boost lib and select one version regular expression libraries.

0
source

The temporary variable from which you want to get matches is used. I think your problem will be solved if you use the following instead of "abc":

 string a("abc); regex_match(a, matches, re.assign("(a)bc")); 
0
source

I had the same problem. I tried the solution posted by Drew Dormann, but that didn't work. Then I found that I was actually contacting 1.40, but for some reason, the headers for 1.37. As soon as I loaded the correct headers (1.40), it stopped segfault.

I noticed this when I compiled using the -g debugging symbols and ran dbg backtrace ..

Hope this helps ...

0
source

All Articles