Skip to content

Instantly share code, notes, and snippets.

@sim642
Last active February 7, 2024 16:43
Show Gist options
  • Save sim642/29caef3cc8afaa273ce6 to your computer and use it in GitHub Desktop.
Save sim642/29caef3cc8afaa273ce6 to your computer and use it in GitHub Desktop.
Installing boost libraries for GCC (MinGW) on Windows

Installing boost libraries for GCC (MinGW) on Windows

Folder setup

  1. Extract downloaded boost source, e.g. C:\Program Files\boost_1_59_0.
  2. Create a folder for Boost.Build installation, e.g. C:\Program Files\boost-build.
  3. Create a folder within for building, i.e. C:\Program Files\boost_1_59_0\build.
  4. Create a folder for installation, e.g. C:\Program Files\boost.

GCC setup

  1. Open Command Prompt.
  2. Run g++ --version.
  3. If the output contains g++ version number then GCC should be set up properly to run from command line and you can continue.

Boost.Build setup

  1. Open Command Prompt and navigate to C:\Program Files\boost_1_59_0\tools\build.
  2. Run bootstrap.bat mingw.
  3. Run b2 install --prefix="C:\Program Files\boost-build".
  4. Add C:\Program Files\boost-build\bin to Windows PATH.

boost building

  1. Open Command Prompt and navigate to C:\Program Files\boost_1_59_0.
  2. Run
b2 --build-dir="C:\Program Files\boost_1_59_0\build" --prefix="C:\Program Files\boost" toolset=gcc install

Project setup

  1. Add include folder, i.e. C:\Program Files\boost\include\boost-1_59.
  2. Add linker folder, i.e. C:\Program Files\boost\lib.
  3. Link required libraries, e.g. libboost_regex-mgw48-mt-1_59.a.
@lawrieb45
Copy link

Solved......................
When first steps done as above the b2.ex was build in the C:\Program Files\boost-build directory.
So the simple solution was to put it into the C:\Program Files\boost_1_73_0 directory
and ran b2 with toolset=gcc (if using gcc). This created all the libs and copied hpp files over to
C:\Program Files\boost-build directory (note this is not inside of the boost root folder)
In CodeBlocks in Compiler settings "Search Directories + Compiler enter
C:\Program Files\boost-build\include\boost-1_73. Its important to point to
boost-1_73 directory otherwise boost hpp files will not work.
There is no need to link the compiler to the C:\Program Files\boost-build\ bin directory
as each project needs to have the appropriate libs attached be aware that there are 2 libs
of each required lib. One for debug and one for release versions for example
Project->Build Options->Linker Settings debug=
..........\Program Files\boost-build\lib\libboost_locale-mgw6-mt-d-x32-1_73.a (notice the "d")
and in the release= ..........\Program Files\boost-build\lib\libboost_locale-mgw6-mt-x32-1_73.a
test it with any of the sample programs at https://www.boost.org/doc/libs/1_73_0/ .
It all works so hope this info helps someone.

@danielTobon43
Copy link

danielTobon43 commented Aug 29, 2020

I just wanna add that:

Boost.Build setup
in:

Open Command Prompt and navigate to C:\Program Files\boost_1_59_0\tools\build.
b2 install --prefix="C:\Program Files\boost-build"
Is ./b2 instead of just b2 since at that moment b2 is not in the path environment.

After adding C:\Program Files\boost-build\bin to Windows PATH.

Now you can use:
b2 --build-dir="C:\Program Files\boost_1_59_0\build" --prefix="C:\Program Files\boost" toolset=gcc install

@Sambhunath-Sahoo
Copy link

i didnt understand this line what sould i include and please help me

Link required libraries, e.g. libboost_regex-mgw48-mt-1_59.a

@lawrieb45
Copy link

Sambhunath
That line is an example only.
In your project you need to add links to libraries that you need for your project
I use Code::Blocks so for me I need to select:
Project
->Build Options
-> Linker Settings
-> Add Libraries
Then navigate to the Boost Bin directory and selecting the needed libs (.a files)
There are 2 files for each lib. 1 for Debug and another for Release version.
Hope that helps ?

@lawrieb45
Copy link

lawrieb45 commented Nov 24, 2020

DigitalAnnoyer
I followed the original instructions at top of page and as I said after searching found
the b2.ex was build in the C:\Program Files\boost-build directory.
So the simple solution was to put it into the C:\Program Files\boost_1_73_0 directory
and ran b2 with toolset=gcc (if using gcc) from command prompt.
Worked for me so cant say much more on that.
I am a rank amature at working with Boost and one of the greatest problems is finding
good examples for using the libraries.
If you get it properly installed then try this site for some good code using Boost
Version is slightly out of date but most samples I have compiled work well.
https://theboostcpplibraries.com/index
To anyone else reading this thread, There is not much more I can help with so would
suggest contacting the original poster.
Also have a look at danielTobon43 post in regards adding to windows path.
Thanks

@StasToken
Copy link

Бесполезная хрень, не работает уже на первом шаге, автор зачем ты тратишь наше время?

@ahmednawazkhan
Copy link

Thank you for saving us. https://gist.github.com/ahmednawazkhan/1c347720af344ee911144ab9f89a1e26 created this for install using MSYS2

@the-overdriven
Copy link

How to fix this error?

vcpkg\packages\boost-build_x64-windows\tools\boost-build\src\engine>copy /b .\b2.exe .\bjam.exe
The system cannot find the file specified.

Failed to build the B2 engine.

@iamBijoyKar
Copy link

I am having this issue on bootstrap.bat mingw or bootstrap.bat gcc. I can't even find the bootstrap.log file.

C:\Program Files\boost_1_62_0\tools\build>bootstrap.bat gcc
Bootstrapping the build engine
Access is denied.

Failed to bootstrap the build engine
Please consult bootstrap.log for furter diagnostics.

image

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