Part of our project requires the use of regular expressions, which are now a part of the C++11 standard. However, getting things working was not completely straight-forward. All our development machines are running Ubuntu 14.04 LTS and we are using CLANG as our default compiler.
Every C++11 regular expression example compiles perfectly using:
$ clang++ -std=c++11 regexp.cc
However, running the program inadvertently results in it crashing each and every time with the following error.
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
Aborted (core dumped)
We thought that it was a problem with the standard library support as regular expressions is part of the C++11 new libraries, not language support. We tested our theory out by switching over to the Boost regular expressions library, which made things work.
So, the solution to the problem is to stick with Boost libraries.
That’s probably the easiest solution for now. Since the C++11 regular expression library is pretty much the Boost library, switching from one to the other is pretty much a matter of changing using statements, and including and linking a different library.
However, since we wanted to get things to work with Ubuntu 14.04 LTS without installing any out of repository packages, we will install the C++11 support libraries for CLANG, which would link against the standard libraries otherwise.
$ apt-get install libc++1 libc++1-dev libc++abi1 libc++abi-dev
Then, compiling the software against it is by using:
$ clang++ -std=c++11 -stdlib=libc++ regexp.cc
After that the program runs properly without crashing.
However, after reading the blog entry by Google’s Chrome team on a similar setup, I think that we will follow their lead and stick to using Boost libraries for now, with an eventual switch over to the standard C++ libraries when things stabilise in the next LTS.
We are already using a number of other Boost libraries in our code. So, adding another Boost library dependency is not going to be an issue for us.
0 Comments