I’m having my first fling with the Boost libraries, and I’ve picked a pretty girl named Regex.
I’ve installed the libraries (which build automatically?) on my machine, but I’m getting the above error (cannot find -lboost_regex). I’m using Code::Blocks with MinGW, and a C++0X compiler flag.
I have
- Pointed the “search directories” to the installation directory
- Added the
-lboost_regexflag to the linker
but no luck. Can someone help me get this working?
Update
Got things running now. I’ve added some further notes in an answer below, for newcomers to this problem.
(Also, changed the title of the question since it turned out to be a broader issue than when I started out.)
I’m not sure what you mean by which build automatically. Most of the Boost libraries are header-only, but a few, such as regex, need to be compiled to a shared / static library. The compilation step is not automatic, you need to invoke the Boost build system (
bjam) to do this. Of course, there are sources (BoostPro for instance) that distribute pre-built Boost binaries for various platforms.Once that’s done, you need to add the path where the libraries are present to the linker’s search path. For MinGW, this option is
-L"path/to/library". Boost does have directives to allow auto-linking of the required libraries, and this seems to work pretty well with MSVC, but I’ve never gotten it to work with MinGW. So you must also list the libraries to be linked explicitly. The Boost libraries include target and version information in the file name by default, so a typical linker command line option will look like-lboost_regex-mgw47-mt-1_51for MinGW gcc 4.7 and Boost 1.51