DEV Community


Posted on

The complicated (Not really) compiling of Boost on Windows for MinGW-W64.

If you use C++ you've probably stumbled upon Boost, a community driven program which creates tons of libraries that are very useful, some of them have even been added to C++ like the filesystem library which has been included since C++17, now I know you're not here to learn about boost but more about how to compile it so let's get to that.

First of all, pick a folder to keep the temporary folders, I like to use C:\temp for my temporary folders and C:\SDKs or C:\libs for my libraries. Once in your temporary folders location, download the version of boost you prefer, for this tutorial I'll be using Boost 1.80.0, you can download it and unzip it using these simple commands:

mkdir C:\temp\boost-b2
mkdir C:\{your-preferred-libraries-location}\boost
tar -xf # Yes this works on Windows or PowerShell at least.
cd boost_1_80_0/tools/build
Enter fullscreen mode Exit fullscreen mode

once in the tools/build folder you'll want to use the bootstrap.bat file supplied with the download to setup Boost.

.\bootstrap.bat gcc

# And now we build
.\b2.exe --prefix="C:\boost-b2" install
Enter fullscreen mode Exit fullscreen mode

And now for the fun part. (Not very fun)
You'll have to return to the C:\temp\boost_1_80_0 folder, and compile the libraries for MinGW using this command

b2 --build-dir="C:\temp\boost_1_80_0\build" --build-type=complete --prefix="C:\{your-preferred-libraries-location}\boost" toolset=gcc install
Enter fullscreen mode Exit fullscreen mode

This will take a while so find something to do while it's compiling.
Once it's done, you can add C:\SDKs to your system environment variables so that CMAKE can easily find Boost. You can also get rid of every folder we created in the C:\temp folder.

Now you can use the Boost library easily! The include folder is C:{your-preferred-libraries-location}\boost\include\boost-1_80 and libraries are stored at C:{your-preferred-libraries-location}\boost\lib. Happy hacking.

Top comments (0)