C++ compile error using boost 1.48-0

I am attempting to compile a simple c++ program that uses boost regex, just to check that all of the libraries / headers have been correctly installed.

/usr/local/include/boost
Contains all of the headers. In particular, for my program:
regex (which is a binary - does anyone know what this is for by the way?)
regex.h - the header declarations for #include directive
regex.hpp - the source for the functions declared in the header

Next, I have:
/usr/local/lib - That contains all of the relevant libraries. Again, for my test program, I am interested in regex libraries:
libboost_regex.a - The static library
libboost_regex.so - The shared / dynamic library
libboost_regex.so.4 - (In passing, I would like to know what this is for)

Now this is the simple toy program that I am trying to compile:
Code:
#include <iostream>
#include <string>
#include <regex.h>

int main()
{
std::string pattern("FreeBSD");
pattern = "[[:alpha:]]*" + pattern + "[[:alpha:]]*";
boost::regex r(pattern);
boost::smatch results;
std::string test_str = "This is a FreeBSD test not a test for freebsd";
if(boost::regex_search(test_str, results, r))
std::cout << results.str() << std::endl;
return 0;
}

I then enter this command to compile the above:
# clang test.cpp -o test -I/usr/local/include/boost -L/usr/local/lib/libboost_regex.so

And this is the output I get:
Code:
"In file included from test.cpp:3:
/usr/local/include/boost/regex.h:22:10: fatal error: 'boost/cregex.hpp' file not found
#include <boost/cregex.hpp>
1 error generated."
The strange thing is that the supposed missing file is in place. Can anyone help with this please?
 
If I use [CMD=]"clang test.cpp -o test -I/usr/local/include -L/usr/local/lib"[/CMD] I get 5 errors relating to use of undeclared identifiers. In other words, the source code references to
Code:
boost::regex, boost::smatch, boost::regex_search
are not understood.
 
I am installing boost 1_52_0

In light of the troubles I have had today, I am removing the 1-48.0 boost and installing the latest available build. Hopefully, everything should work once this is done.

I later found out that the problem had nothing to do with boost 1-48.0 install. The problem was down to the line:

[CMD=]"#include <regex.h>"[/CMD] This is wrong. The correct file to include is:
[CMD=]"#include <regex.hpp>"[/CMD]
 
You are doing inclusion wrong in both situations.

Code:
#include <boost/regex.h>

For the C regex functions.

and

Code:
#include <boost/regex.hpp>

For C++'s version.

This is because all internal inclusion is done with boost/ prefix and you should honor that.
Note that you need to build with -I/usr/local/include.
 
expl said:
You are doing inclusion wrong in both situations.

Code:
#include <boost/regex.h>

For the C regex functions.

and

Code:
#include <boost/regex.hpp>

For C++'s version.

This is because all internal inclusion is done with boost/ prefix and you should honor that.
Note that you need to build with -I/usr/local/include.

Actually [CMD=]"#include <regex.hpp>"[/CMD] is from the boost documentation example in 'getting started'. It is not wrong. Though your comment regarding .h and .hpp is helpful.
 
neilms said:
Actually [CMD=]"#include <regex.hpp>"[/CMD] is from the boost documentation example in 'getting started'. It is not wrong. Though your comment regarding .h and .hpp is helpful.

Well if you open up regex.hpp you will see it imports with "boost/" prefix internally. So there is no real need to compile with "-I/usr/local/include/boost". Also it makes your code more readable if you also include using "boost/" prefix, as then it is self documented that you are using regex from boost.
 
j_m said:
c++ is not so horrible, but boost is.

C++11 supports regex without boost.

Good luck getting C++11 regex working - or even a working C++11 compiler - before 2015!
 
The only C++ compiler I know that std::regex is working is clang version 3.2 (with -std=c++11) and probably later.

Unfortunately I did have to compile it from src (including LLVM 3.2) so it wont yet be very common.

... but I guess it is a tossup between that or dragging in anything from boost as a dependency :/
 
Back
Top