45

I am trying to build boost 1.63 with the lastest msvc 14.1 and VS2017 RC. So I did everything I do normally, I opened the Development Cmd and then I run the bootstrap.bat and run the command

b2 -link=static -threading=multi

For some reason I got those errors :

E:/Coding/SDKs/boost_1_63_0/tools/build/src/tools\msvc.jam:834: in generate-setup-cmd
*** argument error
* rule maybe-rewrite-setup ( toolset : setup-script : setup-options : version : rewrite-setup ? )
* called with: ( msvc :  :  : default :  )
* missing argument setup-script
E:/Coding/SDKs/boost_1_63_0/tools/build/src/tools\msvc.jam:746:see definition of rule 'maybe-rewrite-setup' being called
E:/Coding/SDKs/boost_1_63_0/tools/build/src/tools\msvc.jam:1076: in configure-really
E:/Coding/SDKs/boost_1_63_0/tools/build/src/tools\msvc.jam:201: in configure
E:/Coding/SDKs/boost_1_63_0/tools/build/src/tools\msvc.jam:153: in msvc.init
E:/Coding/SDKs/boost_1_63_0/tools/build/src/build\toolset.jam:43: in toolset.using
E:/Coding/SDKs/boost_1_63_0/tools/build/src/build\project.jam:1052: in using
project-config.jam:3: in modules.load
E:/Coding/SDKs/boost_1_63_0/tools/build/src\build-system.jam:249: in load-config
E:/Coding/SDKs/boost_1_63_0/tools/build/src\build-system.jam:412: in load-configuration-files
E:/Coding/SDKs/boost_1_63_0/tools/build/src\build-system.jam:524: in load
E:\Coding\SDKs\boost_1_63_0\tools\build\src/kernel\modules.jam:295: in import
E:\Coding\SDKs\boost_1_63_0\tools\build\src/kernel/bootstrap.jam:139: in boost-build
E:\Coding\SDKs\boost_1_63_0\boost-build.jam:17: in module scope

I am not familar with boost so maybe one of you could give me a hint

Artur K.
  • 599
  • 1
  • 6
  • 11
  • 1
    The [release notes](http://www.boost.org/users/history/version_1_63_0.html) don't list this compiler as one of those used for testing. Looking at the [sources of boost build](https://github.com/boostorg/build/blob/d1dc47914da6e4f4fde8f2ef6f39ddebe6732239/src/tools/msvc.jam#L1598), it seems it doesn't support this toolset. Since you're not familiar with boost, it may be a good idea to start with a compiler that's supported and tested. – Dan Mašek Jan 04 '17 at 13:28
  • That isn't the issue, I've had the same issue with several versions of visual studio - though it only appears to effect 64bit builds for me. I'm going to post a ticket on the boost tracker and will update here if they respond. – John Bargman Jan 28 '17 at 22:03
  • https://github.com/boostorg/build/issues/157 – KindDragon Jan 31 '17 at 01:16
  • I had this exact problem, and KindDragon's answer solved it for me. I would recommend using that as your 'accepted' answer, simply so that someone else with this problem will know that it is a solution to their immediate problem. I guess it doesn't go as far as solving the underlying problem (hence having to 'trick' b2 rather than this being a default behaviour), but it suffices for the time being. – Jake Feb 12 '17 at 18:59
  • You can also use vcpkg instead to get boost. – Damian Aug 15 '18 at 08:55

4 Answers4

89

Based on KindDragons and CPlusPlus OOA and D answers I compiled Boost 1.63. For 64bit. Run "x64 Native Tools Command Prompt for VS 2017" command prompt:

1) Run: bootstrap.bat

2) open project-config.jam. Here is mine:

import option ; 

using msvc : 14.0 : "c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64\cl.exe"; 

option.set keep-going : false ;

The part: 14.10.25017 keep changing with updates to your Windows SDK. So update it accordingly.

3) Run b2 toolset=msvc-14.0 address-model=64

Nick
  • 1,248
  • 12
  • 18
  • 5
    If only I could up-vote this twice... I almost created a second account just for that.. – George Newton Mar 22 '17 at 19:37
  • 1
    With the Visual Studio 2017, Update 2, only the x64 Native Tools prompt correctly finds the ml64.exe assembler executable (e.g. ml.exe for x86 and ml64.exe for x64). For x64, every time I use the Developer Tools prompt, the response is, `"'ml64' is not recognized as an internal or external command, operable program or batch file."` However, please note that x64 Boost output files correctly occur with the _**x64 Native Tools prompt**_. The x86 aka Win32 Boost output files correctly happen with the 2017 _**Developer Tools**_ prompt. Only one Developer Tools prompt shortcut exists (e.g. x86). – CPlusPlus OOA and D Jun 20 '17 at 13:54
  • Is it just me, or does this not work anymore with boost 1.67.0? – JHBonarius Jun 16 '18 at 10:12
  • 1.67.0 supports VS2017 without above shenanigans. Look below in KindDragon answer: run appropriate command prompt (x86 or x64 Native Tools Command Prompt), then bootstrap.bat, then: 32-bit: b2 toolset=msvc-14.1 --build-dir=.x86 --stagedir=stage_x86 or for 64bit: b2 toolset=msvc-14.1 address-model=64 --build-dir=.x64 --stagedir=stage_x64 – Nick Jun 17 '18 at 17:39
  • 2
    you are the champion! – JQ. Nov 29 '18 at 07:47
39

Boost 1.63 doesn't fully support VS2017, but you can trick it to find VC++2017 compiler:

  1. Run bootstrap.bat in boost directory
  2. Update the project-config.jam to include: using msvc : 14.0 : <path to x86 or x64 cl.exe>. Should be something like "c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.24911\bin\HostX64\x64\cl.exe"
  3. Run "Developer Command Prompt for VS 2017 RC" from Windows Start Menu to boostrap from a shell configured using the x86 vcvars or x64 vcvars.
  4. Run b2 toolset=msvc-14.0 in that command prompt. For the x64 build, add address-model=64 to the b2 command line.

UPDATE: Boost 1.64 should support VS2017

Run "x86 Native Tools Command Prompt for VS 2017" or "x64 Native Tools Command Prompt for VS 2017" from Start Menu, than inside command prompt run b2:

32-bit: b2 toolset=msvc-14.1 --build-dir=.x86 --stagedir=stage_x86

64-bit: b2 toolset=msvc-14.1 address-model=64 --build-dir=.x64 --stagedir=stage_x64

Add link=shared to build shared libraries

KindDragon
  • 6,558
  • 4
  • 47
  • 75
  • 1
    this pretty much did the trick for me! I did have to change (2) to look like this though: `using msvc : 14.0 : "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64\cl.exe"` or else there is an error `error: msvc initialization: parameter 'version' inconsistent` – sail0r May 09 '17 at 20:27
  • For me this solution worked when I used the path to cl.exe without quotes. I am trying to use VS2019 for boost 1.62. `using msvc : 14.2 : C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29333\bin\Hostx64\x64\cl.exe ;` – Sahil Singh Aug 17 '21 at 16:01
13

I've created a batch script which builds both 32 and 64 bits binaries in the following github repo: https://github.com/manuelgustavo/boost_build

The secret lies in using Visual Studio 2017's Developer Command Prompt. It sets all environment variables as needed.

Then from it, you can execute something like:

for 32 bit :

b2.exe --toolset=msvc-14.0 architecture=x86 address-model=32 --stagedir=".\stage32" threading=multi --build-type=complete stage

and for the 64 bit :

b2.exe --toolset=msvc-14.0 architecture=x86 address-model=64 --stagedir=".\stage64" threading=multi --build-type=complete stage

Or if you prefer, just go to https://github.com/manuelgustavo/boost_build and follow the steps from there.

Olórin
  • 3,367
  • 2
  • 22
  • 42
manuel saraiva
  • 601
  • 6
  • 5
  • Lovely!!! You should add the information to the script that it needs to be started from vs command prompt btw – Viktor Sehr Mar 30 '17 at 10:32
  • 1
    you can also just run "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars(32/64).bat" to set the env variables for a standard cmd. – TheBat Apr 18 '17 at 14:26
  • 1
    Why do we have `architecture=x86` even for the 64 bits build ? – Olórin Jun 09 '18 at 10:12
1

One more tip for build with Visual Studio 2017 which worked in my case. If you already built Boost with older version of Visual Studio, delete temporary batch files generated by Boost bootstrap script located in your user's TEMP folder e.g.:

C:\Users\MYUSER~1\AppData\Local\Temp\b2_msvc_14.1_vcvarsx86_amd64_.cmd

The solution comes from this thread: http://boost.2283326.n4.nabble.com/Building-boost-fails-with-VS2017-v15-5-2-td4700909.html

tommyk
  • 3,187
  • 7
  • 39
  • 61