7

I'm working on a new project which requires Boost's regex library. I was able to use the no-compile headers, but needed some of the binaries which require being compiled. Boost's documentation for compiling in Visual Studio wasn't very helpful (resulted in several errors) and I've seen a fair number of people online having these same problems, but it took a lot of Googling to get them all, so I've included detailed steps below to help anyone with the same issues.

I'm running Windows 10 preview and Visual Studio 11 (2012), but the steps should work for other versions as well.

Step 1 - Set up a developer command prompt in Visual Studio

You will need this to compile the binaries. The VS Command window (Ctrl+W,A) didn't seem to work.

1. In VS , select "Tools" at the top, then select "External Tools" and enter the following:
    -Title: "VS2013 Native Tools-Command Prompt" (your choice)
    -Command: C:\Windows\System32\cmd.exe
    -Arguments: /k "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat"  (make sure to use the correct path to your version of VS)
    -Initial Directory: Select as suits your needs (if you'll use boost a bunch, I'd select the folder where you dropped boost)
2. Click OK. Now you have command prompt access under the same "Tools" menu, where it will show up as a new option.

Source: https://stackoverflow.com/questions/21476588/where-is-developer-command-prompt-for-vs2013

Step 2 - Run Bootstrap.bat from VS developer command prompt

1. Navigate to your Boost folder (mine is C:\Program Files\boost\boost_1_58_0)
2. Run `.\Bootstrap.bat` which results in the following error:

    > 'cl' is not recognized as an internal or external command"

    Cl.exe is is a tool that controls the Microsoft C and C++ compilers and linker.  This error is because cl.exe is not in your path environment variable; it isn't automatically added when you install VS. Check by running the following:
    -In PowerShell - `($env:path).replace(';',"`n")` (easy to read)
    -In cmd.exe - `echo %path%` (harder to read)  

 4. Add cl.exe to your path by adding its parent folder "C:\Program Files (x86)\Microsoft Visual Studio [your version]\VC\bin"
    -Hit Win+X -> System -> Advanced System Settings -> Environment Variables -> Select "Path" under System Variables (in bottom pane) -> Edit -> paste the following to the end: ";C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin" (don't forget the semicolon on the front)
    -Test by opening a new command prompt or PowerShell window and type `cl.exe -?`

Step 3 - Re-run bootstrap with cl.exe in your path

You may be missing some environment variables for Visual Studio, resulting in the following error:

mspdb110.dll not found

1. Navigate to the Visual Studio path in your Visual Studio developer command prompt (for me it's C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin) 
2. Run `.\vcvars32.bat` which automatically sets some variables for you, but there is no output -- lack of error means likely success

Step 4 - Compile the Boost binaries

Now running .\Bootstrap.bat in your Visual Studio developer command prompt should succeed and you can now use the binaries in your project!

Wes H
  • 99
  • 1
  • 6
  • So, what's the question? – Igor R. Jun 25 '15 at 05:23
  • 1
    I was just putting this up to help anyone trying to do the same thing, since it took me several hours to figure this all out. I joined just so I could share this (I've used a million articles and figured it's time to give back). Is there a better place for me to put this? – Wes H Jun 26 '15 at 23:21
  • Are you using those binaries with Windows Universal Apps? – MarcinG Aug 12 '15 at 10:37
  • I haven't tried them with Universal Apps, but if that requires additional steps, we can update the steps above with them as well. – Wes H Sep 02 '15 at 21:03
  • 1
    It didn't work for me, because the instruction is not complete. After step 4 one should run the `b2` command in cmd.exe, from the boost directory. It builds library binaries (it is long proccess). After that go to Project->Properties->Linker->General->Additional Library Directories. Add "[boost_directory_path]\stage\lib". [Boost docs with this step](http://www.boost.org/doc/libs/1_60_0/more/getting_started/windows.html#simplified-build-from-source) – re-gor Apr 07 '16 at 10:25
  • @WesH, you should pose a question, and answer your own question with what you explained here. – Jorge Leitao Jan 24 '17 at 09:53
  • 1
    _As a side note:_ in order to share your knowledge in the form of a self-answered question you should've written an answer not inside the question section, but as a separate answer (there is a checkbox that says "**Answer your own question**" at the bottom of the Ask Question page). It would be much easier for everybody to read a _dedicated_ answer (and you can also **accept** your own answer). Read more here: https://stackoverflow.com/help/self-answer – informatik01 Jul 15 '19 at 09:32

0 Answers0