A note to Cygwin and MinGW users
If you plan to use your tools from the Windows command prompt,
you’re in the right place. If you plan to build from the Cygwin
bash shell, you’re actually running on a POSIX platform and
should follow the instructions for getting started on Unix
variants. Other command shells, such as MinGW’s MSYS, are
not supported—they may or may not work.
Index
- 1 Get Boost
- 2 The Boost Distribution
- 3 Header-Only Libraries
- 4 Build a Simple Program Using Boost
- 4.1 Build From the Visual Studio IDE
- 4.2 Or, Build From the Command Prompt
- 4.3 Errors and Warnings
- 5 Prepare to Use a Boost Library Binary
- 5.1 Simplified Build From Source
- 5.2 Or, Build Binaries From Source
- 5.2.1 Install Boost.Build
- 5.2.2 Identify Your Toolset
- 5.2.3 Select a Build Directory
- 5.2.4 Invoke b2
- 5.3 Expected Build Output
- 5.4 In Case of Build Errors
- 6 Link Your Program to a Boost Library
- 6.1 Link From Within the Visual Studio IDE
- 6.2 Or, Link From the Command Prompt
- 6.3 Library Naming
- 6.4 Test Your Program
- 7 Conclusion and Further Resources
2 The Boost Distribution
This is a sketch of the resulting directory structure:
boost_1_82_0 .................The “boost root directory” index.htm .........A copy of www.boost.org starts here boost .........................All Boost Header files lib .....................precompiled library binaries libs ............Tests, .cpps, docs, etc., by library index.html ........Library documentation starts here algorithm any array …more libraries… status .........................Boost-wide test suite tools ...........Utilities, e.g. Boost.Build, quickbook, bcp more ..........................Policy documents, etc. doc ...............A subset of all Boost library docs
It’s important to note the following:
-
The path to the boost root directory (often C:Program Filesboostboost_1_82_0) is
sometimes referred to as $BOOST_ROOT in documentation and
mailing lists . -
To compile anything in Boost, you need a directory containing
the boost subdirectory in your #include path. Specific steps for setting up #include
paths in Microsoft Visual Studio follow later in this document;
if you use another IDE, please consult your product’s
documentation for instructions. -
Since all of Boost’s header files have the .hpp extension,
and live in the boost subdirectory of the boost root, your
Boost #include directives will look like:#include <boost/whatever.hpp>
or
#include "boost/whatever.hpp"
depending on your preference regarding the use of angle bracket
includes. Even Windows users can (and, for
portability reasons, probably should) use forward slashes in
#include directives; your compiler doesn’t care. -
Don’t be distracted by the doc subdirectory; it only
contains a subset of the Boost documentation. Start with
libsindex.html if you’re looking for the whole enchilada.
4 Build a Simple Program Using Boost
To keep things simple, let’s start by using a header-only library.
The following program reads a sequence of integers from standard
input, uses Boost.Lambda to multiply each number by three, and
writes them to standard output:
#include <boost/lambda/lambda.hpp> #include <iostream> #include <iterator> #include <algorithm> int main() { using namespace boost::lambda; typedef std::istream_iterator<int> in; std::for_each( in(std::cin), in(), std::cout << (_1 * 3) << " " ); }
Copy the text of this program into a file called example.cpp.
4.1 Build From the Visual Studio IDE
-
From Visual Studio’s File menu, select New > Project…
-
In the left-hand pane of the resulting New Project dialog,
select Visual C++ > Win32. -
In the right-hand pane, select Win32 Console Application
(VS8.0) or Win32 Console Project (VS7.1). -
In the name field, enter “example”
-
Right-click example in the Solution Explorer pane and
select Properties from the resulting pop-up menu -
In Configuration Properties > C/C++ > General > Additional Include
Directories, enter the path to the Boost root directory, for exampleC:Program Filesboostboost_1_82_0
-
In Configuration Properties > C/C++ > Precompiled Headers, change
Use Precompiled Header (/Yu) to Not Using Precompiled
Headers.2 -
Replace the contents of the example.cpp generated by the IDE
with the example code above. -
From the Build menu, select Build Solution.
To test your application, hit the F5 key and type the following
into the resulting window, followed by the Return key:
1 2 3
Then hold down the control key and press «Z», followed by the
Return key.
skip to the next step
4.2 Or, Build From the Command Prompt
From your computer’s Start menu, if you are a Visual
Studio 2005 user, select
All Programs > Microsoft Visual Studio 2005
> Visual Studio Tools > Visual Studio 2005 Command Prompt
or, if you’re a Visual Studio .NET 2003 user, select
All Programs > Microsoft Visual Studio .NET 2003
> Visual Studio .NET Tools > Visual Studio .NET 2003 Command Prompt
to bring up a special command prompt window set up for the
Visual Studio compiler. In that window, set the current
directory to a suitable location for creating some temporary
files and type the following command followed by the Return key:
cl /EHsc /I pathtoboost_1_82_0 pathtoexample.cpp
To test the result, type:
echo 1 2 3 | example
4.3 Errors and Warnings
Don’t be alarmed if you see compiler warnings originating in Boost
headers. We try to eliminate them, but doing so isn’t always
practical.4 Errors are another matter. If you’re
seeing compilation errors at this point in the tutorial, check to
be sure you’ve copied the example program correctly and that you’ve
correctly identified the Boost root directory.
5 Prepare to Use a Boost Library Binary
If you want to use any of the separately-compiled Boost libraries,
you’ll need to acquire library binaries.
5.1 Simplified Build From Source
If you wish to build from source with Visual C++, you can use a
simple build procedure described in this section. Open the command prompt
and change your current directory to the Boost root directory. Then, type
the following commands:
bootstrap .b2
The first command prepares the Boost.Build system for use. The second
command invokes Boost.Build to build the separately-compiled Boost
libraries. Please consult the Boost.Build documentation for a list
of allowed options.
5.2 Or, Build Binaries From Source
If you’re using an earlier version of Visual C++, or a compiler
from another vendor, you’ll need to use Boost.Build to create your
own binaries.
5.2.1 Install Boost.Build
Boost.Build is a text-based system for developing, testing, and
installing software. First, you’ll need to build and
install it. To do this:
- Go to the directory toolsbuild.
- Run bootstrap.bat
- Run b2 install —prefix=PREFIX where PREFIX is
the directory where you want Boost.Build to be installed - Add PREFIXbin to your PATH environment variable.
5.2.3 Select a Build Directory
Boost.Build will place all intermediate files it generates while
building into the build directory. If your Boost root
directory is writable, this step isn’t strictly necessary: by
default Boost.Build will create a bin.v2/ subdirectory for that
purpose in your current working directory.
5.2.4 Invoke b2
Change your current directory to the Boost root directory and
invoke b2 as follows:
b2 --build-dir=build-directory toolset=toolset-name --build-type=complete stage
For a complete description of these and other invocation options,
please see the Boost.Build documentation.
For example, your session might look like this:3
C:WINDOWS> cd C:Program Filesboostboost_1_82_0 C:Program Filesboostboost_1_82_0> b2 ^ More? --build-dir="C:Documents and Settingsdavebuild-boost" ^ More? --build-type=complete msvc stage
Be sure to read this note about the appearance of ^,
More? and quotation marks («) in that line.
The option “—build-type=complete” causes Boost.Build to build
all supported variants of the libraries. For instructions on how to
build only specific variants, please ask on the Boost Users’ mailing
list.
Building the special stage target places Boost
library binaries in the stagelib subdirectory of
the Boost tree. To use a different directory pass the
—stagedir=directory option to b2.
Note
b2 is case-sensitive; it is important that all the
parts shown in bold type above be entirely lower-case.
For a description of other options you can pass when invoking
b2, type:
b2 --help
In particular, to limit the amount of time spent building, you may
be interested in:
- reviewing the list of library names with —show-libraries
- limiting which libraries get built with the —with-library-name or —without-library-name options
- choosing a specific build variant by adding release or
debug to the command line.
Note
Boost.Build can produce a great deal of output, which can
make it easy to miss problems. If you want to make sure
everything is went well, you might redirect the output into a
file by appending “>build.log 2>&1” to your command line.
5.3 Expected Build Output
During the process of building Boost libraries, you can expect to
see some messages printed on the console. These may include
-
Notices about Boost library configuration—for example, the Regex
library outputs a message about ICU when built without Unicode
support, and the Python library may be skipped without error (but
with a notice) if you don’t have Python installed. -
Messages from the build tool that report the number of targets
that were built or skipped. Don’t be surprised if those numbers
don’t make any sense to you; there are many targets per library. -
Build action messages describing what the tool is doing, which
look something like:toolset-name.c++ long/path/to/file/being/built
-
Compiler warnings.
5.4 In Case of Build Errors
The only error messages you see when building Boost—if any—should
be related to the IOStreams library’s support of zip and bzip2
formats as described here. Install the relevant development
packages for libz and libbz2 if you need those features. Other
errors when building Boost libraries are cause for concern.
If it seems like the build system can’t find your compiler and/or
linker, consider setting up a user-config.jam file as described
here. If that isn’t your problem or the user-config.jam file
doesn’t work for you, please address questions about configuring Boost
for your compiler to the Boost Users’ mailing list.
6 Link Your Program to a Boost Library
To demonstrate linking with a Boost binary library, we’ll use the
following simple program that extracts the subject lines from
emails. It uses the Boost.Regex library, which has a
separately-compiled binary component.
#include <boost/regex.hpp> #include <iostream> #include <string> int main() { std::string line; boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" ); while (std::cin) { std::getline(std::cin, line); boost::smatch matches; if (boost::regex_match(line, matches, pat)) std::cout << matches[2] << std::endl; } }
There are two main challenges associated with linking:
- Tool configuration, e.g. choosing command-line options or IDE
build settings. - Identifying the library binary, among all the build variants,
whose compile configuration is compatible with the rest of your
project.
Auto-Linking
Most Windows compilers and linkers have so-called “auto-linking
support,” which eliminates the second challenge. Special code in
Boost header files detects your compiler options and uses that
information to encode the name of the correct library into your
object files; the linker selects the library with that name from
the directories you’ve told it to search.
The GCC toolchains (Cygwin and MinGW) are notable exceptions;
GCC users should refer to the linking instructions for Unix
variant OSes for the appropriate command-line options to use.
6.1 Link From Within the Visual Studio IDE
Starting with the header-only example project we created
earlier:
- Right-click example in the Solution Explorer pane and
select Properties from the resulting pop-up menu - In Configuration Properties > Linker > Additional Library
Directories, enter the path to the Boost binaries,
e.g. C:Program Filesboostboost_1_82_0lib. - From the Build menu, select Build Solution.
skip to the next step
6.2 Or, Link From the Command Prompt
For example, we can compile and link the above program from the
Visual C++ command-line by simply adding the bold text below to
the command line we used earlier, assuming your Boost binaries are
in C:Program Filesboostboost_1_82_0lib:
cl /EHsc /I pathtoboost_1_82_0 example.cpp ^ /link /LIBPATH:C:Program Filesboostboost_1_82_0lib
6.3 Library Naming
Note
If, like Visual C++, your compiler supports auto-linking,
you can probably skip to the next step.
In order to choose the right binary for your build configuration
you need to know how Boost binaries are named. Each library
filename is composed of a common sequence of elements that describe
how it was built. For example,
libboost_regex-vc71-mt-d-x86-1_34.lib can be broken down into the
following elements:
- lib
- Prefix: except on Microsoft Windows, every Boost library
name begins with this string. On Windows, only ordinary static
libraries use the lib prefix; import libraries and DLLs do
not.5 - boost_regex
- Library name: all boost library filenames begin with boost_.
- -vc71
- Toolset tag: identifies the toolset and version used to build
the binary. - -mt
- Threading tag: indicates that the library was
built with multithreading support enabled. Libraries built
without multithreading support can be identified by the absence
of -mt. - -d
-
ABI tag: encodes details that affect the library’s
interoperability with other compiled code. For each such
feature, a single letter is added to the tag:Key Use this library when: Boost.Build option s linking statically to the C++ standard library and compiler runtime support
libraries.runtime-link=static g using debug versions of the standard and runtime support libraries. runtime-debugging=on y using a special debug build of Python. python-debugging=on d building a debug version of your code.6 variant=debug p using the STLPort standard library rather than the default one supplied with
your compiler.stdlib=stlport For example, if you build a debug version of your code for use
with debug versions of the static runtime library and the
STLPort standard library,
the tag would be: -sgdp. If none of the above apply, the
ABI tag is ommitted. - -x86
-
Architecture and address model tag: in the first letter, encodes the architecture as follows:
Key Architecture Boost.Build option x x86-32, x86-64 architecture=x86 a ARM architecture=arm i IA-64 architecture=ia64 s Sparc architecture=sparc m MIPS/SGI architecture=mips* p RS/6000 & PowerPC architecture=power The two digits following the letter encode the address model as follows:
Key Address model Boost.Build option 32 32 bit address-model=32 64 64 bit address-model=64 - -1_34
- Version tag: the full Boost release number, with periods
replaced by underscores. For example, version 1.31.1 would be
tagged as «-1_31_1». - .lib
- Extension: determined according to the operating system’s usual
convention. On most unix-style platforms the extensions are
.a and .so for static libraries (archives) and shared
libraries, respectively. On Windows, .dll indicates a shared
library and .lib indicates a
static or import library. Where supported by toolsets on unix
variants, a full version extension is added (e.g. «.so.1.34») and
a symbolic link to the library file, named without the trailing
version number, will also be created.
6.4 Test Your Program
To test our subject extraction, we’ll filter the following text
file. Copy it out of your browser and save it as jayne.txt:
To: George Shmidlap From: Rita Marlowe Subject: Will Success Spoil Rock Hunter? --- See subject.
Now, in a command prompt window, type:
pathtocompiledexample < pathtojayne.txt
The program should respond with the email subject, “Will Success
Spoil Rock Hunter?”
7 Conclusion and Further Resources
This concludes your introduction to Boost and to integrating it
with your programs. As you start using Boost in earnest, there are
surely a few additional points you’ll wish we had covered. One day
we may have a “Book 2 in the Getting Started series” that addresses
them. Until then, we suggest you pursue the following resources.
If you can’t find what you need, or there’s anything we can do to
make this document clearer, please post it to the Boost Users’
mailing list.
- Boost.Build reference manual
- Boost Users’ mailing list
- Index of all Boost library documentation
Onward
Good luck, and have fun!
—the Boost Developers
[1] | We recommend downloading boost_1_82_0.7z and using 7-Zip to decompress it. We no longer recommend .zip files for Boost because they are twice as large as the equivalent .7z files. We don’t recommend using Windows’ built-in decompression as it can be painfully slow for large archives. |
[2] | There’s no problem using Boost with precompiled headers; these instructions merely avoid precompiled headers because it would require Visual Studio-specific changes to the source code used in the examples. |
[3] |
In this example, the caret character ^ is a The command prompt treats each bit of whitespace in the command --build-dir="C:Documents_and_Settingsdavebuild-boost" Also, for example, you can’t add spaces around the = sign as in --build-dir_=_"C:Documents and Settingsdavebuild-boost" |
[4] | Remember that warnings are specific to each compiler implementation. The developer of a given Boost library might not have access to your compiler. Also, some warnings are extremely difficult to eliminate in generic code, to the point where it’s not worth the trouble. Finally, some compilers don’t have any source code mechanism for suppressing warnings. |
[5] | This convention distinguishes the static version of a Boost library from the import library for an identically-configured Boost DLL, which would otherwise have the same name. |
[6] | These libraries were compiled without optimization or inlining, with full debug symbols enabled, and without NDEBUG #defined. Although it’s true that sometimes these choices don’t affect binary compatibility with other compiled code, you can’t count on that with Boost libraries. |
Boost library is a set of a popular collection of peer-reviewed, free, open-source C++ libraries. It supports a number of tasks such as unit testing, image processing, multithreading, and mathematical aspects such as linear algebra and regular expressions. You can also store, numbers that are out of range of long long, or double. It was first made available on September 1st, 1999. There are 164 different libraries in it. In this article, we will learn, how to install the boost library in C++ on Windows.
Installing Boost Library in C++ on Windows:
Step 1: Go to Boost.org. Click on the Downloads option on the right side.
Step 2: Click on the boost_1_72_0.zip file, to download the required boost library. It has an approx. size of 200MB.
Step 3: Now, open the location where your zip file is downloaded. For example: This PC > Local Disk (C:) > Users > jh > Downloads > .
Step 4: Select the zip file. Right-Click on it, and select Extract All…
Step 5: The files get extracted at the same location, with the same folder name. Now, go to Program Files, and create a new folder name Boost.
Step 6: Now, copy the extracted folder boost_1_72_0 into the boost folder. Hence, the boost library is installed into our system.
Verify the Installation of the Boost Library in C++
The successful compilation of the code will prove that the boost library is installed in windows.
C++
#include <boost/array.hpp>
#include <iostream>
using
namespace
std;
int
main()
{
boost::array<
int
, 10> arr
= { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } };
for
(
int
i = 0; i < 10; i++) {
cout <<
"Geek Rank is :"
<< arr[i] <<
"*"
<<
"n"
;
}
return
0;
}
Output:
Geek Rank is :1* Geek Rank is :2* Geek Rank is :3* Geek Rank is :4* Geek Rank is :5* Geek Rank is :6* Geek Rank is :7* Geek Rank is :8* Geek Rank is :9* Geek Rank is :10*
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 Filesmingw-w64x86_64-8.1.0-posix-seh-rt_v6-rev0mingw64"
Add MinGW to the system PATH
Add this to the session and system PATH environment variable
set PATH=%PATH%;C:MinGWbin
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:installboost_1_68_0.zip C:install"
This takes about 15 minutes
cd C:installboost_1_68_0
Make directories for building and install
mkdir C:boost-build
mkdir C:installboost_1_68_0boost-build
mkdir C:boost
Boost.Build setup
cd C:installboost_1_68_0toolsbuild
prepare b2
bootstrap.bat gcc
Build boost.build with b2
b2 --prefix="C:boost-build" install
Add C:boost-buildbin to your session PATH variable
set PATH=%PATH%;C:boost-buildbin
Building Boost
navigate back up to the boost unzipped root directory
cd C:installboost_1_68_0
Build boost with b2
b2 --build-dir="C:installboost_1_68_0build" --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:boostincludeboost-1_68
Linker folder:
C:boostlib
Link required libraries:
e.g. libboost_atomic-mgw81-mt-d-x64-1_68.a
Boost libraries are some of the famous ones in the C++ world.
They contain tons of functionalities but aren’t so easy to use or even understand.
First things first, let’s try to install it in on our dear Windows 10 operating system (it should work as well on Windows 11).
And test it with Visual Studio 2017 and Visual Studio 2019.
Ready? Let’s do it in this Boost installation tutorial for Windows 10.
First of all
We are going to set up our computer in order to use the following libraries and software:
- Visual Studio 2017 (feel free to use Visual Studio 2019, more information in this tutorial)
- Boost 1.71.0 libraries with the binaries (boost_1_71_0-msvc-14.1-64.exe)
Note the 14.1 version what is corresponding to MSVC 141 in order to be used with MSVC 2017.
For the MSVC 2019, please do the same but with the 14.2 version what is related to the MSVC 142 and download the Boost 1.77.0 version.
Setting up Boost libraries
Downloading and installing Boost libraries
The Boost libraries are in general available directly without building anything (only by including headers).
But some libraries have to be built before being able to use them.
That’s the case for example for the Boost.Python or Boost.Regex libraries.
It’s possible to build these libraries by yourself but to be honest the Boost documentation isn’t really crystal clear and some links are even broken.
So to avoid a headache from the sky we are going to use the binaries directly downloaded from SourceForge (link above).
This executable isn’t really an installation but more an extraction.
Indeed nothing will be changed on your Windows registries, only a new directory will be created with some files within.
So, once the executable donwloaded, Windows will show you a blue window with a message alerting that this is an unrecognized app.
Click on More info at the end of this message to make the Run anyway push button appear.
For MVSC 2017, install it in the following location:
- C:softboost_1_71_0
For MVSC 2019, install it in the following location:
- C:softboost_1_77_0
In this directory you can now see another one called lib64-msvc-14.1/ (for MSVC 2017) or lib64-msvc-14.2 (for MSVC 2019) in which there are built libraries, all that in an x64 environment.
Building the Boost.Build (b2) engine (optional feature for this tutorial)
If you want to build libraries from Boost on your own way you’ll have to use the Boost.Build tool.
It was in the past called bjam but it’s now called b2.
So these 2 tools are exactly the same but the latter is the new version used with Boost.Build.
When you download Boost from the official website, b2 isn’t installed.
You have to do it by yourself.
Actually it’s quite easy.
Open a console from the Boost directory (depending on your MSVC version 141 or 142):
- C:softboost_1_71_0
or
- C:softboost_1_77_0
Then type the following command:
.bootstrap.bat
And you’ll have on your console after few seconds this message:
PS C:softboost_1_71_0> .bootstrap.bat Building Boost.Build engine Generating Boost.Build configuration in project-config.jam for msvc... Bootstrapping is done. To build, run: .b2 To adjust configuration, edit 'project-config.jam'. Further information: - Command line help: .b2 --help - Getting started guide: http://boost.org/more/getting_started/windows.html - Boost.Build documentation: http://www.boost.org/build/
In the same directory you can now see the b2.exe tool.
We don’t need it for now, just let it for the future.
Environment variables for Boost
We have to set our Environment variables.
So add the 2 following paths for MSVC 2017:
- C:softboost_1_71_0
- C:softboost_1_71_0lib64-msvc-14.1
And for MSVC 2019:
- C:softboost_1_77_0
- C:softboost_1_77_0lib64-msvc-14.2
If you are using Windows 10 it’s not so unusual to use Visual Studio as well.
So let’s set it up to use Boost.
Setting up Visual Studio
Visual Studio platform toolset
If your Visual Studio instance was already opened then close it and open it again to get the new Environment variable modifications.
We are going to use Visual Studio 2017 so the binaries version are 14.1.
Or the Visual Studio 2019 with binaries 14.2.
Indeed, each version of Visual Studio has its own platform toolset.
For example:
- Visual Studio 2017 has a platform toolset 14.1 (often msvc-141)
- Visual Studio 2019 has a platform toolset 14.2 (often msvc-142)
Yes it’s quite vague and not so logical but Miscrosoft is Microsoft.
So download the right one for your Visual Studio version, otherwise it won’t work.
Anyway let’s set up all that tools.
I’ll let you install Visual Studio where you want.
We’ll just have to set the include and library directories directly from Visual Studio.
Let’s start by creating a Windows Console Application from Visual Studio.
From Visual Studio > File > New Project > Installed > Visual C++ > Windows Desktop > Windows Console Application.
Let’s name this project for example like this:
- Name: BadprogTutorial
- Location: C:devc++boost
Setting the Visual Studio project platform
First thing is now to change the project platform in the Configuration manager:
From Visual Studio > Select the BadprogTutorial.cpp file > Project > BadprogTutorial Properties… > On upper right click the Configuration Mananger… push button > Change Active solution platform from x86 to x64 > Close.
Then still in the BadprogTutorial Property Pages, at top center, change the platform from Win32 to x64.
Then click OK.
You can stay in Debug mode or change it to Release (it won’t change anything for our tutorial).
Setting Visual Studio include paths for Boost
First let’s set the includes.
From Visual Studio > Select the BadprogTutorial.cpp file > Project > BadprogTutorial Properties… > Configuration Properties > C/C++ > General > Additional Include Directories > Edit > Add the following line:
- C:softboost_1_71_0
or
- C:softboost_1_77_0
Then OK > Apply > OK.
Setting Visual Studio library paths for Boost
We’ve now to set the libraries.
Same thing but with the linker:
From Visual Studio > Select the BadprogTutorial.cpp file > Project > BadprogTutorial Properties… > Configuration Properties > Linker > General > Additional Library Directories > Edit > Add the following line:
- C:softboost_1_71_0lib64-msvc-14.1
or
- C:softboost_1_77_0lib64-msvc-14.2
Then OK > Apply > OK.
Let’s code a bit
In our BadprogTutorial.cpp file let’s add the following code:
BadprogTutorial.cpp
// badprog.com
#include «pch.h»
#include <boost/date_time/gregorian/gregorian.hpp>
#include <iostream>
//
namespace bg = boost::gregorian;
// —————————————————————————-
//
// —————————————————————————-
int main() {
// date as simple ISO string
std::string stringDate(«20191110»);
bg::date todayDate(bg::from_undelimited_string(stringDate));
//
bg::date::ymd_type ymdDate = todayDate.year_month_day();
bg::greg_weekday weekdayDate = todayDate.day_of_week();
//
std::cout
<< «Tutorial made with love from Badprog.com on «
<< weekdayDate.as_long_string() << » «
<< ymdDate.day << » «
<< ymdDate.month.as_long_string() << » «
<< ymdDate.year
<< std::endl;
}
Build and run
Build and run your program, you should see the following appears on your console:
Tutorial made with love from Badprog.com :D on Sunday 10 November 2019
Conclusion
Now that you have installed Boost, plenty of libraries are now available for you.
A lot of fun for the future.
Good job, you did it.
This package contains the Boost C++ Libraries development files.
Install Boost (Ubuntu)
Usually, you’ll want to install all available Boost libraries. Note that you will be prompted for your password upon using sudo
.
sudo apt install libboost-all-dev
In case you just want specific components of the Boost framework, check available packages (libboost-<component>-dev
) first. For Boost.Thread:
sudo apt install libboost-thread-dev
Header-only Boost libraries are grouped in one single package, which is a common dependency for libboost-all-dev
and libboost-<component>-dev
:
sudo apt install libboost-dev
Install Boost (Windows)
- Download the source code from http://www.boost.org/users/download/.
- Extract in a
Boost
folder located atC:
orC:Program files
so that CMake find-modules can detect it. - Invoke the command line and navigate to the extracted folder (e.g.
cd C:Boostboost_1_63_0
). - Follow the instructions at http://www.boost.org/build/doc/html/bbv2/overview/invocation.html to build all packages in the selected configuration. You may want to compile only specific modules, in which case refer to their documentation (http://www.boost.org/doc/libs/).
- Run the bootstrap script (
bootstrap.bat
) prior to building anything. - Issuing
b2
will build only static libraries for the default architecture and both Release and Debug configurations. - Issue
b2 variant=release address-model=64 link=static,shared
to build 64-bit static and dynamic binaries in Release configuration for all available Boost components. - Issue
b2 property=value --with-<component>
to build only specific Boost components (list). Use lower case. Example:b2 variant=release --with-thread
will build release binaries for Boost.Thread. You can chain multiple--with-<component>
options. - See #Properties for further details on the command line interface.
- Run the bootstrap script (
results matching ««
No results matching ««
You cannot currently build Boost with Preview, but you can with the regular 2019 just released. I had this same issue. It takes like ten minutes to install 2019 regular with required features. You can have both at the same time.
For future reference, here are my notes for how to build boost on windows with MPI and python support.
Building Boost on Windows with VS 2019
Need Visual Studio 2019 Non-Preview, any version, all the C++ and Windows SDK stuff.
Note: temporarily uninstall the C++ and Windows SDK stuff from VS Preview if you have both. Ideally have only one compiler on the system so Boost.build
doesn’t get confused.
Next, assuming you have git-for-windows installed, execute
git clone https://github.com/boostorg/boost.git --recursive
the boost superproject repo to an UNPROTECTED folder called /Boost/
(must be unprotected!)
cd boost
Now your in /Boost/boost
.
Checkout the developer branch (get recent updates) with
git checkout develop -f
Where -f forces updates.
Run bootstrap inside the boost folder using Visual Studio Developer Console. To activate this console, either use the Windows search bar «Type here to search» for «Developer Command Prompt», or open visual studio and use the search bar at the top.
Note: If you are getting access errors, you have to activate administrative visual studio developer console.
Open cmd
in administrative mode and run VsDevCmd.bat, the file that activates the visual studio developer console.
bootstrap
If you haven’t already done so, install Microsoft MPI by installing both files available for latest version of Microsoft MPI.
Its known to be working with Version 10, requires installing BOTH the SDK (an .msi file) and non-SDK (a .exe file) files to the DEFAULT locations. Do not modify these locations.
Then modify project-config.jam in the /Boost/boost/
directory to the following:
(btw, there is white space [a regular space] after each line, even empty lines)
# Boost.Build Configuration
# Automatically generated by bootstrap.bat
import option ;
using msvc ;
option.set keep-going : false ;
using python ;
using mpi ;
The last two lines assume you want mpi and python support.
Now open Visual Studio Developer Console and navigate (cd) to the boost folder /Boost/boost
. Since we’re using the Visual C++ compiler from VS 2019, apparently we don’t need to b2 install
anything (see sections 5.1 — 5.2 in the Getting Started guide). Then the only thing we need next is to run
b2 -j8 --address-model=64
Options include
--toolset=14.xx
[to specify vs compiler version 14.15, etc] (ortoolset
without the--
, someone told me, not sure which is correct please let me know, for me it was--
)-a
for rebuild all-j8
for 8 cores compilation--address-model=64
(oraddress-model
without the--
, someone told me, not sure which is correct please let me know, for me it was--
) for 64-bit> my_log.txt
at the end to record the ridiculous amounts of text output from the build, for later use (making sure it went ok).
Since most of these command line tools were developed for Unix, and Unix
style, platforms they are an awkward fit for windows and recipes requires
more effort. This leads to two possible techniques, firstly install with
cygwin which handles much of the complexity for you, but requires that
you always use it from within Cygwin. The other is to manually install
the toolchain for use from the windows command prompt. This gives a more
integrated user experience but is quite fiddly to get right.
These instruction assume that cygwin has been installed to c:cygwin
.
Install these packages:
-
Libs/libxml2
-
Libs/libxslt
-
Text/docbook-xml42
-
Text/docbook-xsl
-
Devel/gcc4-g++
(optional, if you don’t have
a compiler). -
Devel/doxygen
(optional, for generating reference
documentation from C++ source files).
Now we need to configure Boost.Build to use these tools. This step
is different depending on whether you’re using Boost.Build built with
cygwin, or for native windows. For cygwin you need to add to your
user-config.jam
file:
using xsltproc ; using boostbook : /usr/share/docbook-xsl : /usr/share/xml/docbook/4.2 ; using quickbook ; # If you installed doxygen: using doxygen ;
When using a native (non-Cygwin) Boost.Build, you’ll need to specify
the windows paths to the various tools:
# Adjust this path to the location of your cygwin install. CYGWIN_DIR = c:/cygwin ; using xsltproc : $(CYGWIN_DIR)/bin/xsltproc.exe ; using boostbook : $(CYGWIN_DIR)/usr/share/docbook-xsl : $(CYGWIN_DIR)/usr/share/xml/docbook/4.2 ; using quickbook ; # If you installed doxygen: using doxygen : $(CYGWIN_DIR)/bin/doxygen.exe ;
In order to install the tools under windows, we need to create a directory
structure somewhat similar to the unix filesystem. We’re going to place
this in c:boost-tools
, if you want to put it elsewhere,
just follow the instructions, adjusting the paths accordingly. This
is also a good location to use as the prefix when installing Boost.Build.
-
Create directory for boost tools, say
c:boost-tools
. -
Create directory for binaries,
c:boost-toolsbin
. -
Add the
bin
directory to the path (e.g. in Xp,
right click on ‘My Computer’, click on ‘Properties’, then the ‘Advanced’
tab and click on ‘Environment variables’ to open a dialog where
you can edit the PATH variable).
Next you need to download several xml tools from Igor
Zlatkovic. You require: iconv
, libxml2
and libxslt
, zlib
. Then unzip
these into the c:boost-tools
directory. This should
place the xsltproc
exectuable in c:boost-toolsbin
.
Next make a directory for xml processing files at c:boost-toolsxml
.
-
Norman Walsh’s DocBook
XSL stylesheets from their package_id=16608
Sourceforge download page toc:boost-toolsxmldocbook-xsl
. -
The DocBook
DTD toc:boost-toolsxmldocbook-xml
.
user-config.jam
in the boost build search path,
for most people this will be C:Documents and Settingsusername
.
BOOST_TOOLS_DIR = c:/boost-tools ; using xsltproc : $(BOOST_TOOLS_DIR)/bin/xsltproc.exe" ; using boostbook : $(BOOST_TOOLS_DIR)/xml/docbook-xsl : $(BOOST_TOOLS_DIR)/xml/docbook-xml ; using quickbook ;
Also, if you wish to use doxygen to generate reference documentation
from C++ source headers, you’ll need to install it. You can download
it from the
doxygen website. The installer should add the executable to
your path, so you just need to add to your user-config.jam
:
using doxygen ;
If you’re using Snow Leopard (OS X 10.6) or later, then you should already
have the xml tools installed, so you just need to install the docbook
xml and xslt files. The easiest way to do that is probably to use macports,
install them with:
sudo port install docbook-xml-4.2 docbook-xsl
For earlier versions of OS X, you’ll also need to install libxslt
to get an up to date version of xsltproc
:
sudo port install libxslt docbook-xml-4.2 docbook-xsl
You can also install doxygen
, for generating reference documentation
from C++ source files:
sudo port install doxygen
Boost.Build knows the default install location for macports, so all you
need to add to your user-config.jam
is an instruction to
use them:
using boostbook ; using quickbook ; # If you've installed doxygen: using doxygen ;
Installing on Debian and Ubuntu is pretty easy, just install the packages
using apt-get
(or an alternative, such as aptitude
):
sudo apt-get install xsltproc docbook-xsl docbook-xml
You can also install doxygen
, for generating reference documentation
from C++ source files:
sudo apt-get install doxygen
Boost.Build should be to find these packages without an explicit path,
so just add to your user-config.jam
:
using boostbook ; using quickbook ; # If you've installed doxygen: using doxygen ;