Skip to content

Instantly share code, notes, and snippets.

@rjl6789
Forked from zrsmithson/mngw-w64_boost.MD
Created September 6, 2019 10:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjl6789/baef53c2a3c7d5492dde76dcf0dd12f3 to your computer and use it in GitHub Desktop.
Save rjl6789/baef53c2a3c7d5492dde76dcf0dd12f3 to your computer and use it in GitHub Desktop.
Installing boost on Windows using MinGW-w64 (gcc 64-bit)

Installing boost on Windows using MinGW-w64 (gcc 64-bit)

Introduction

Boost is easy when you are using headers or pre-compiled binaries for visual studio, but it can be a pain to compile from source on windows, especially when you want the 64-bit version of MinGW to use gcc/g++. This installation process should be thorough enough to simply copy and paste commands, but robust enough to install everything you need.

Note: if you need to install any of the libraries that need dependencies, see this great answer from stack overflow

Get files needed for install

Get the MinGW installer mingw-w64-install.exe from Sourceforge
Get the boost_1_68_0.zip source from Sourceforge
Note: This should work perfectly with other versions of boost as well
Copy these to a new folder
C:\install
It should now contain the following two files

  • mingw-w64-install.exe
  • boost_1_68_0.zip

Install MinGW-w64

Run the installer

Run mingw-w64-install.exe
Click next
Change the Architecture from i868 to x86_64

Click next and keep the default install location
Click next to start the install
Click Finish to exit the installer

After the install, add a hard link (junction) to the folder

Open a command prompt AS ADMIN

  • windows key -> type "cmd"
  • right click "command prompt"
  • Run as administrator
    Enter the following command to create a link to MinGW folder in C:\
    mklink /J C:\MinGW "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64"

Add MinGW to the system PATH

Add this to the session and system PATH environment variable
set PATH=%PATH%;C:\MinGW\bin
setx /M PATH "%PATH%"
Check to ensure proper install
g++ --version should return the following info

Install boost

Navigate to install

cd C:\install

unzip to "install/boost_1_68_0"

powershell -command "Expand-Archive C:\install\boost_1_68_0.zip C:\install"
This takes about 15 minutes
cd C:\install\boost_1_68_0

Make directories for building and install

mkdir C:\boost-build
mkdir C:\install\boost_1_68_0\boost-build
mkdir C:\boost

Boost.Build setup

cd C:\install\boost_1_68_0\tools\build
prepare b2
bootstrap.bat gcc
Build boost.build with b2
b2 --prefix="C:\boost-build" install
Add C:\boost-build\bin to your session PATH variable
set PATH=%PATH%;C:\boost-build\bin

Building Boost

navigate back up to the boost unzipped root directory
cd C:\install\boost_1_68_0
Build boost with b2
b2 --build-dir="C:\install\boost_1_68_0\build" --build-type=complete --prefix="C:\boost" toolset=gcc install
This is going to take awhile, so try to run this command right before beginning the director's cut of Lord of the Ring Return of the King.
When this is done you should see the following output

You can now delete "C:\install" and "C:\boost-build"

Adding to projects

Everything should now be installed
Include folder:
C:\boost\include\boost-1_68
Linker folder:
C:\boost\lib
Link required libraries:
e.g. libboost_atomic-mgw81-mt-d-x64-1_68.a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment