Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Boost libraries with MinGW and CodeBlocks

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

like image 965
Ben Avatar asked Jun 23 '26 22:06

Ben


1 Answers

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)
    • Some aging basic documentation on that
  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!

like image 94
Ben Avatar answered Jun 26 '26 10:06

Ben