2

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_regex flag 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.)

Ben
  • 54,723
  • 49
  • 178
  • 224
  • 'which build automatically?' There's your mistake I think. http://www.boost.org/doc/libs/1_52_0/libs/regex/doc/html/boost_regex/install.html – john Nov 10 '12 at 07:47
  • What did you do to install the libraries? In my experience, you either get a boost package that has the libraries already built (such as with the nuwen MinGW distribution and the BoostPro package or boost.teeks99.com for MSVC boost libraries) or you build them yourself. I'm not familiar with an install that *builds* them 'automatically' (though I'd be happy to learn about such a thing). – Michael Burr Nov 10 '12 at 07:52
  • Oh. That could be it. I just downloaded the installer and ran it. I thought I read somewhere that it built everything at the same time. Anyway, I've been trying to build myself using http://www.boost.org/doc/libs/1_52_0/libs/regex/doc/html/boost_regex/install.html but there's a new set of problems...guess I'll focus my energies there instead. – Ben Nov 10 '12 at 07:57
  • You have to add path to Boost libraries to the linker's search path as Praetorian pointed. Btw, do you get this error when linking? – SChepurin Nov 10 '12 at 10:39
  • @SChepurin yes, but it turns out I hadn't built the libraries yet. I'd only added the variable to the linker, and pointed the compiler to the header files. – Ben Nov 11 '12 at 09:15

2 Answers2

6

Here's some links and tips that can help a newcomer, from my first build experience. I built the libraries directly from the zip file. I built on MinGW and I used CodeBlocks for the IDE.

  1. Download Boost zip, unzip somewhere (I'll call that place $boostdir)
    • Pretty large when unzipped, > 300MB
  2. Add MinGW bin to PATH var
    • When Boost builds, it will need access to MinGW executables
  3. Build b2.exe and bjam.exe
    • The documentation for Windows blithely assumes MSVC compiler is available.
    • If it is, you can apparently use the bootstrap.bat like the docs say.
    • If it's not (like mine), you'll have to build the exe files yourself, in steps 4 and 5.
  4. In CMD, navigate to $boostdir/tools/build/v2/engine
  5. Run build.bat mingw (will build b2.exe and bjam.exe)
  6. Now you've got b2 and bjam custom-built according to your system spec. Navigate back up to $boostdir and get ready to start building the libraries.
    • Boost will make a new bin.v2 directory in the current directory.
    • All the libs will go in bin.v2.
    • This is an "intermediate" directory, for some reason
    • Nothing to do in this step, just some extra info :)
  7. Run b2 toolset=gcc --build-type=complete
    • This takes a long time, in the neighborhood of 1 - 2 hours.
    • You'll know if it's working. If you think something's wrong, it's not working.
    • The build can use various flags

Now you're all built. Time to set up CodeBlocks.

  1. Point your compiler to the header files
    • Right click your project -> Build Options -> Search Directories tab -> Compiler tab -> add $boostdir address
  2. Boost has built a DLL for the library you want according to your current system spec. Look in the stage\lib\ directory of $boostdir
    • This DLL will be used later in the linker, so don't close its explorer window yet
    • Mine was in C:\Program Files\Boost_1_52\stage\lib\libboost_regex-mgw44-1_52.dll
    • I think the documentation had a smart way to do this but I haven't tried it yet
    • The "intermediate" directory from step #6 can be deleted now that the build is finished
  3. Point your linker to the directory of that DLL
    • Right click your project -> Build Options -> Search Directories tab -> Linker tab -> add that directory address (blah\blah\blah\stage\lib\)
  4. Add that DLL flag to your linker settings
    • Mine was -lboost_regex-mgw44-1_52
  5. Deep breath, prayers to your god, and fire up a test.

Further docs that may either help or confuse:

The Code::Blocks website has a version of this that I didn't find until I neared the end of my search. It was fairly helpful but had a few weird things. This post also is helpful.

Good luck!

Community
  • 1
  • 1
Ben
  • 54,723
  • 49
  • 178
  • 224
  • `bootstrap.bat` does default to MSVC on Windows, but you can override this by running `bootstrap.bat mingw`, and save yourself the trouble of navigating into subdirectories. – Praetorian Nov 12 '12 at 01:15
4

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_51 for MinGW gcc 4.7 and Boost 1.51

Praetorian
  • 106,671
  • 19
  • 240
  • 328
  • Oh, I see now. The lib has to be built separately depending on the compiler being used, so of course Boost wouldn't distribute all the different builds. Thanks for the help. – Ben Nov 10 '12 at 08:01
  • Boom finally got it. Thanks muchly. – Ben Nov 11 '12 at 09:26