Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.
@RafaelMH
Copy link

RafaelMH commented Sep 27, 2017

Thank you so much for this, I was starting to get desperate.

Also, as of boost 1.65.1 you should still change bootstrap.bat mingw to boostrap.bat gcc.

@Sk3pper
Copy link

Sk3pper commented Oct 1, 2017

I don't understand the last part, "Project setup". What have I to do? Where have I to add that folders (lib, include ecc)?

@vitor-alves
Copy link

vitor-alves commented Oct 18, 2017

bootstrap.bat mingw worked for me in 1.65.1

@BramVanroy
Copy link

BramVanroy commented Jul 6, 2018

I'm also confused about the last part. Could you elaborate on this? What should be linked and how.

@andyspurgeon
Copy link

andyspurgeon commented Jul 13, 2018

Just a note that for Boost 1.67.0, I had to go back to bootstrap.bat gcc instead of mingw. Not sure if that's something in the Boost build system or my setup, but it worked.

@BramVanroy, the project setup depends on what you are developing using Boost. Boost is composed of multiple libraries. So, you typically don't include/link all of Boost -- you only use what you need. See this link for a list of the individual Boost libraries.

@zrsmithson
Copy link

zrsmithson commented Sep 20, 2018

When running the first b2, no toolset is given. Does this matter for the first build? When run it gives:

warning: No toolsets are configured.
warning: Configuring default toolset "msvc".
warning: If the default is wrong, your build may not work correctly.
warning: Use the "toolset=xxxxx" option to override our guess.
warning: For more configuration options, please consult
warning: http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html

warning: Did not find command for MSVC toolset. If you have Visual Studio 2017 installed you will need to specify the full path to the command, set VS150COMNTOOLS for your installation, or build from the 'Visual Studio Command Prompt for VS 2017'.

@kailashkai28
Copy link

kailashkai28 commented Oct 11, 2018

bootstrap.bat gcc is working for all the boost versions.

@mitevdev
Copy link

mitevdev commented Oct 31, 2018

bootstrap.bat gcc completed successfully but when I run b2 install --prefix="C:\Program Files\boost-build I get

warning: No toolsets are configured.
warning: Configuring default toolset "msvc".
warning: If the default is wrong, your build may not work correctly.
warning: Use the "toolset=xxxxx" option to override our guess.
warning: For more configuration options, please consult
warning: http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html

bootstrap.log looks fine all sources have been compiled successfully.

UPDATE: I had to give full access to the user on c:\Program Files\boost-build and it worked.

Copy link

ghost commented Nov 3, 2018

warning: No toolsets are configured.
warning: Configuring default toolset "msvc".
warning: If the default is wrong, your build may not work correctly.
warning: Use the "toolset=xxxxx" option to override our guess.
warning: For more configuration options, please consult
warning: http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html
"C:\Program" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
error: no Jamfile in current directory found, and no target references specified.
I'm running cmd.exe in administrator mode.

@RichardTMiles
Copy link

RichardTMiles commented Dec 21, 2018

Hero, saint, and scholar. Thank you!

@zafaryabRasool
Copy link

zafaryabRasool commented Apr 5, 2019

How to do project setup point 3?

following the whole procedure, when i run my code, it says:
fatal error: boost/geometry/geometries/geometries.hpp: No such file or directory.

Any reasons?

@Trans-SVSR
Copy link

Trans-SVSR commented May 30, 2019

what to do with :
Project setup!!!!!!!!!!!!!!!!

@Greg-Tarr
Copy link

Greg-Tarr commented Jun 12, 2019

bootstrap.bat mingw works in 1_55_0. It works if you have mingw set up correctly in PATH.

@Pirgosth
Copy link

Pirgosth commented Jul 10, 2019

You can reduce significantly compilation time for the second b2 step by adding the -j N parameter where N is the number of thread you want (it can be little higher than number of core of your CPU) according to here:
https://stackoverflow.com/questions/33566782/building-all-of-boost-in-a-few-minutes

@sconuk
Copy link

sconuk commented Sep 1, 2019

Great article, I had been pulling my hair out for a few hours. Thanks!

@shscampbell
Copy link

shscampbell commented Sep 12, 2019

I looked into the mingw argument for bootstrap.bat. The mingw section of tools\build\src\engine\config_toolset.bat for Boost 1.66.0 looks like
if NOT "_%BOOST_JAM_TOOLSET%_" == "_mingw_" goto Skip_MINGW
if not "_%BOOST_JAM_TOOLSET_ROOT%_" == "__" (
set "PATH=%BOOST_JAM_TOOLSET_ROOT%bin;%PATH%"
)
set "BOOST_JAM_CC=gcc -DNT"
set "BOOST_JAM_OPT_JAM=-o bootstrap\jam0.exe"
set "BOOST_JAM_OPT_MKJAMBASE=-o bootstrap\mkjambase0.exe"
set "BOOST_JAM_OPT_YYACC=-o bootstrap\yyacc0.exe"
set "_known_=1"
:Skip_MINGW

It is the same as for "gcc" except at the beginning it adds %BOOST_JAM_TOOLSET_ROOT%bin to the front of PATH if the variable is defined. This is a convenient thing to do if you want to specify which gcc to use, or if you don't want gcc in your system PATH.

The problem is that the batch needs to set "BOOST_JAM_TOOLSET=gcc" to call the jam0 command with --toolset=gcc since toolset=mingw is not supported.

So my understanding is:

  • if gcc is in your PATH, just use "bootstrap.bat gcc",

  • if you want to define BOOST_JAM_TOOLSET_ROOT to specify a bin subfolder containing the gcc you want to use, then add the missing line
    set "BOOST_JAM_TOOLSET=gcc"
    to the mingw section of bootstrap.bat and use "bootstrap.bat mingw".

@shscampbell
Copy link

shscampbell commented Sep 13, 2019

Another note: the build will fail if the path to the build directory has too many characters. You will receive mysterious "No such file or directory" errors as full path filenames get truncated under the hood. You need to keep the build directory close to the top of the directory tree on the hard drive.

@shaharyar0312
Copy link

shaharyar0312 commented Oct 13, 2019

this command bootstrap.bat mingw didn't work for me too, then i run cmd as an administrator and done :)

Copy link

ghost commented Oct 13, 2019

Hello guys :)
I tried to do this instruction and get the error while compiling:
C:/Develop/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -llibboost_unit_test_framework-mgw73-mt-x64-1_71.a

My instruction at Makefile:
all:
g++ -o test test/Test.cpp -I C:/Develop/boost/include/boost-1_71 -L C:/Develop/boost/lib -llibboost_unit_test_framework-mgw73-mt-x64-1_71.a

Test.cpp file:
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE Hello
#include <boost/test/unit_test.hpp>

int add( int i, int j )
{
return i + j;
}

BOOST_AUTO_TEST_CASE( testAdd )
{
BOOST_CHECK( add( 2, 2 ) == 4 );
}

Any suggestion? I fight with this a lot of time. I use MinGW 7.3.0 and Visual Studio Code on Windows

@ananvodo
Copy link

ananvodo commented Apr 4, 2020

Hi,

I have this error.
I am using gcc 9.2.0 and boost_1_72_0 library

Using 'gcc' toolset.

C:\Program Files\boost_1_72_0\tools\build\src\engine>g++ -x c++ -std=c++11 -s -O3 -o b2.exe -DNDEBUG builtins.cpp class.cpp command.cpp compile.cpp constants.cpp cwd.cpp debug.cpp debugger.cpp execcmd.cpp execnt.cpp filent.cpp filesys.cpp frames.cpp function.cpp glob.cpp hash.cpp hcache.cpp hdrmacro.cpp headers.cpp jam.cpp jambase.cpp jamgram.cpp lists.cpp make.cpp make1.cpp md5.cpp mem.cpp modules.cpp native.cpp object.cpp option.cpp output.cpp parse.cpp pathnt.cpp pathsys.cpp regexp.cpp rules.cpp scan.cpp search.cpp strings.cpp subst.cpp sysinfo.cpp timestamp.cpp variable.cpp w32_getreg.cpp modules/order.cpp modules/path.cpp modules/property-set.cpp modules/regex.cpp modules/sequence.cpp modules/set.cpp

C:\Program Files\boost_1_72_0\tools\build\src\engine>dir *.exe
Volume in drive C is Local Disk
Volume Serial Number is 46E6-2CA0

Directory of C:\Program Files\boost_1_72_0\tools\build\src\engine

C:\Program Files\boost_1_72_0\tools\build\src\engine>copy /b .\b2.exe .\bjam.exe
The system cannot find the file specified.

Please help me how to solve this issue.

Thanks

@sai56
Copy link

sai56 commented Jun 3, 2020

Hi,

I have this error.
I am using gcc 9.2.0 and boost_1_72_0 library

Using 'gcc' toolset.

C:\Program Files\boost_1_72_0\tools\build\src\engine>g++ -x c++ -std=c++11 -s -O3 -o b2.exe -DNDEBUG builtins.cpp class.cpp command.cpp compile.cpp constants.cpp cwd.cpp debug.cpp debugger.cpp execcmd.cpp execnt.cpp filent.cpp filesys.cpp frames.cpp function.cpp glob.cpp hash.cpp hcache.cpp hdrmacro.cpp headers.cpp jam.cpp jambase.cpp jamgram.cpp lists.cpp make.cpp make1.cpp md5.cpp mem.cpp modules.cpp native.cpp object.cpp option.cpp output.cpp parse.cpp pathnt.cpp pathsys.cpp regexp.cpp rules.cpp scan.cpp search.cpp strings.cpp subst.cpp sysinfo.cpp timestamp.cpp variable.cpp w32_getreg.cpp modules/order.cpp modules/path.cpp modules/property-set.cpp modules/regex.cpp modules/sequence.cpp modules/set.cpp

C:\Program Files\boost_1_72_0\tools\build\src\engine>dir *.exe
Volume in drive C is Local Disk
Volume Serial Number is 46E6-2CA0

Directory of C:\Program Files\boost_1_72_0\tools\build\src\engine

C:\Program Files\boost_1_72_0\tools\build\src\engine>copy /b .\b2.exe .\bjam.exe
The system cannot find the file specified.

Please help me how to solve this issue.

Thanks

Were you able to fix this issue ?

@lawrieb45
Copy link

lawrieb45 commented Jul 29, 2020

Hi
I have followed all of your suggested proceedures both as user and admin but come up with the following.
am on windows 8.1 boost v 1_73_0 g++6.3.0 (MinGW GCC)
Hope you can help with this problelm
Lawrie

Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Windows\system32>cd C:\Program Files\boost_1_73_0\tools\build

C:\Program Files\boost_1_73_0\tools\build>bootstrap.bat gcc
Building the B2 engine..

Using 'gcc' toolset.

C:\Program Files\boost_1_73_0\tools\build\src\engine>g++ -x c++ -std=c++11 -s -O3 -o b2.exe -DNDEBUG builtins.cpp class.cpp command.cpp compile.cpp constants.cpp cwd
.cpp debug.cpp debugger.cpp execcmd.cpp execnt.cpp filent.cpp filesys.cpp frames.cpp function.cpp glob.cpp hash.cpp hcache.cpp hdrmacro.cpp headers.cpp jam.cpp jambase.
cpp jamgram.cpp lists.cpp make.cpp make1.cpp md5.cpp mem.cpp modules.cpp native.cpp object.cpp option.cpp output.cpp parse.cpp pathnt.cpp pathsys.cpp regexp.cpp rules.c
pp scan.cpp search.cpp jam_strings.cpp subst.cpp sysinfo.cpp timestamp.cpp variable.cpp w32_getreg.cpp modules/order.cpp modules/path.cpp modules/property-set.cpp modul
es/regex.cpp modules/sequence.cpp modules/set.cpp
builtins.cpp: In function 'FILE* windows_popen_wrapper(const char*, const char*)':
builtins.cpp:2487:39: error: '_popen' was not declared in this scope
result = _popen( command, "r" );
^
builtins.cpp: In function 'LIST* builtin_shell(FRAME*, int)':
builtins.cpp:2553:29: error: '_pclose' was not declared in this scope
exit_status = pclose( p );
^
debugger.cpp: In function 'char* debug_string_read(FILE*)':
debugger.cpp:110:33: error: 'strdup' was not declared in this scope
result = strdup( buf->value );
^
debugger.cpp: In function 'void debug_init_handles(const char*, const char*)':
debugger.cpp:1046:43: error: '_fdopen' was not declared in this scope
command_input = _fdopen( read_fd, "r" );
^
debugger.cpp: In function 'void init_parent_handles(HANDLE, HANDLE)':
debugger.cpp:1062:78: error: '_fdopen' was not declared in this scope
command_child = _fdopen( _open_osfhandle( (intptr_t)in, _O_RDONLY ), "r" );
^
execnt.cpp:58:28: fatal error: versionhelpers.h: No such file or directory
#include <versionhelpers.h>
^
compilation terminated.
jam.cpp: In function 'int main(int, char**, char**)':
jam.cpp:200:22: error: 'environ' was not declared in this scope

define use_environ environ

                  ^

jam.cpp:561:37: note: in expansion of macro 'use_environ'
var_defines( root_module(), use_environ, 1 );
^~~~~~~~~~~
jam.cpp: In function 'char* executable_path(const char*)':
jam.cpp:735:66: error: 'strdup' was not declared in this scope
return ( !ret || ret == sizeof( buf ) ) ? NULL : strdup( buf );
^
sysinfo.cpp: In function 'unsigned int {anonymous}::std_thread_hardware_concurrency()':
sysinfo.cpp:93:21: error: 'std::thread' has not been declared
return std:🧵:hardware_concurrency();
^~~~~~

C:\Program Files\boost_1_73_0\tools\build\src\engine>dir *.exe
Volume in drive C is Windows
Volume Serial Number is B084-B251

Directory of C:\Program Files\boost_1_73_0\tools\build\src\engine

File Not Found

C:\Program Files\boost_1_73_0\tools\build\src\engine>copy /b .\b2.exe .\bjam.exe
The system cannot find the file specified.

Failed to build the B2 engine.

C:\Program Files\boost_1_73_0\tools\build>

@lawrieb45
Copy link

lawrieb45 commented Aug 2, 2020

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

Sambhunath-Sahoo commented Oct 28, 2020

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

lawrieb45 commented Oct 30, 2020

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

StasToken commented Mar 25, 2021

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

@ahmednawazkhan
Copy link

ahmednawazkhan commented Nov 6, 2021

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

@the-overdriven
Copy link

the-overdriven commented Feb 21, 2022

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.

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