pBook‎ > ‎BOOST C++‎ > ‎

### Boost MinGw Gcc Windows

posted Dec 1, 2014, 3:51 PM by Javad Taghia   [ updated Dec 1, 2014, 5:51 PM ]

Install MinGw on your system. I recommend using the same bit system as your processor is. Then set the path in System Environment to the bin folder which contains g++, make... files. Now you are ready to go.

1. For obvious reasons, start a fresh terminal (cmd.exe), don't use the already open terminals that don't know your new setting.

2. Download boost, the latest stable release, unzip it and in the command window follow the path too the main directory of the extracted boost.

3. Run this command: bootstrap mingw

4. Run this command afterwards, which will install in the folder you select as your destination.

b2 install --prefix=c:\boost\1.54.0\gcc toolset=gcc

5. In eclipse you need to set the path for libs and includes.

6. libs are in the installed folder, but keep in mind that the names are a bit weird like libboost_chrono-mgw49-mt-1_56 so you need to add like

7. boost_chrono-mgw49-mt-1_56 as your lib file and path should be c:\boost\1.54.0\gcc\lib

8. include is in C:\Boost\1.56.0\gcc\include\boost-1_56\boost

9. Now run the test program comes below.

# How to install the C++ Boost Libraries on Windows

Boost is a set of high-quality libraries that speed up C++ development. They are included in most linux distributions and some of them are already part of the C++ Standard Library. In the Windows environment, you have to install them in order to take advantage of them.

Before we start, you may want to read my previous article on installing a C++ compiler on Windows.

## Installation

Download and unzip the boost source code from http://www.boost.org/. I will unzip it to C:optc-libs, but you can use the one you prefer. After you unzip, open a command line and go to your selected folder:

cd C:optc-libsboost_1_51_0

Start bootstrap.bat and specify your toolset. Toolsets supported by this script are: borland, como, gcc, gcc-nocygwin, intel-win32, metrowerks, mingw, msvc, vc7, vc8, vc9, vc10, vc11. In my case I will use the mingw toolset:

bootstrap.bat mingw

All required files for compilation should be ready. Now you have to define a installation directory and specify a toolset. Toolsets here are a little bit different from the ones we used before:

• acc: Hewlett Packard, Only very recent versions are known to work well with Boost
• borland: borland
• como: Comeau Computing, Using this toolset may require configuring another toolset to act as its backend
• darwin: Apple, Apple’s version of the GCC toolchain with support for Darwin and MacOS X features such as frameworks.
• gcc: The Gnu Project, including Cygwin and MinGW
• hp_cxx: Hewlett Packard, Targeted at the Tru64 operating system.
• intel: Intel
• msvc: Microsoft
• sun: Sun, Only very recent versions are known to work well with Boost.
• vacpp: IBM, The VisualAge C++ compiler.

Since I’m using MinGW I will use gcc.

b2 install --prefix=c:/installation/path toolset=gcc

At this time you can go get a cup of coffee. Or maybe two.

When compilation ends, go to your selected installation path (watch out!, this is not the folder where you originally unzipped the source code). You will find two folders: include and lib. Both folders should contain files. That means you are done and ready for the testing phase.

If any of the afore mentioned folders is empty then we have problems. Common problems arise due to selecting the wrong toolset for compiling, so if your lib folder is empty try choosing a different toolset. If error persist, take a look at the compilation output. Errors must be shown there, specially at the last lines of the output.

## Testing

From your IDE create a file named main.cpp and copy the following text onto it:

#include <boost/regex.hpp>
#include
#include

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;
}
}

### It’s time to compile (and link)

In order to let your compiler know where to look for the headers and libraries, you have to follow the next steps. You can usually accomplish them by right clicking on your project and selecting Properties or Options.

C:/installation/path/include/boost-version

C:/installation/path/lib

Important: if you are using Netbeans, you should only type /installation/path/lib (you have to omit the C:). For a very strange reason, Netbeans adds a forward slash at the beggining of the parameter /L used to compile (only when it begins with C:) resulting in an unknown path. This might be fixed in later versions.

If you are using a gnu compiler (that is Cygwin or MinGW), you must also add the specific library to the linker. If you are using Microsoft Visual Studio you can skip this step because it includes the so called auto-linking support. But, in my case, I have to add the following library to my libraries list so the linker performs without complaints:

C:/installation/path/lib/libboost_regex-mgw47-mt-1_51.a

This file name is composed by:

• The standard lib prefix. DLL’s do not use it.
• The library name boost_regex.
• The toolset used to compile it, in my case mgw47, that is MinGW version 4.7.
• The threading tag mt, which indicates if the library accepts multithreading.
• The ABI tag, that can be: d for debugging, s for static linkage or gyp which are not covered in this text.
• The version tag.
• The extension, which can be .lib or .a.

You are ready. Build the program.

### Time to execute it

The program you just compiled (and linked) can parse a text file looking for a line starting with the text “Subject:” in it. So to test it, copy and paste the following text into an empty text file and name ittest.txt (save it in the folder where your .exe file resides):

To: George Shmidlap
From: Rita Marlowe
Subject: Will Success Spoil Rock Hunter?
---
See subject.

Now, from a command prompt type:

yourprogram.exe < test.txt

If everything goes right you should see the following text:

Will Success Spoil Rock Hunter?