h1

How to Install, Build and Use the Boost C++ libraries for development with the Eclipse IDE using the MinGW compiler on a Windows Platform

August 24, 2010

This article outlines how to install, build and use the Boost C++ libraries for development with the Eclipse IDE using the MinGW compiler on a Windows platform.  The article will cover all steps including:

  • Downloading and installing the Eclipse C++ IDE.
  • Downloading and installing the MinGW (GCC, G++, GDB, etc) compiler toolchain.
  • Downloading and installing the Boost library sources.
  • Compiling and running a simple program that uses the Boost header files only.
  • How to build the complete set of Boost binary libraries.
  • How to configure a C++ project in Eclipse IDE to include and link the Boost C++ binary libraries.
  • Finally, we will compile and run a simple program to verify the Boost libraries are correctly installed, built and can be used by your C++ projects.

Overview

We begin by providing a brief overview of the various software components we use in this article.  All of the software components mentioned in this article are free to use for opensource and commercial development.  There are some excellent resources and tutorials included in the references section at the end of this article.  In particular, I have provided references to free online tutorials for C++ programming, and cookbook recipes for C++ and the Boost Libraries.  A cookbook is a collection of hundreds of practical solutions (recipes) to problems that programmers face, with the goal of demonstrating a language’s capabilities and the relative simplicity of implementing them.

What are the Boost C++ libraries?

The Boost C++ Libraries are a collection of free libraries that extend the functionality of C++.  The current Boost release contains over 80 individual libraries (an overview of the libraries are provided here).

Why should a developer/organization use the Boost Libraries?

  • In a word, Productivity. High-quality libraries like Boost speeds initial development, results in fewer bugs, reduces reinvention-of-the-wheel, and cuts long-term maintenance costs.
  • The Boost C++ libraries are open-source and peer-reviewed.
  • The Boost C++ libraries are platform independent and work on almost any modern operating system, including UNIX and Windows variants.
  • The Boost C++ libraries complements the Standard Template Library (STL) rather than replaces it.
  • The Boost C++ libraries are well documented.
  • Most of the Boost libraries are licensed under the Boost Software License, designed to allow Boost to be used with both free and proprietary software projects.

What is the Eclipse C++ IDE?

The Eclipse CDT Project provides a fully functional C and C++ Integrated Development Environment based on the Eclipse platform. Features include: support for project creation and managed build for various toolchains, standard make build, source navigation, various source knowledge tools, such as type hierarchy, call graph, include browser, macro definition browser, code editor with syntax highlighting, folding and hyperlink navigation, source code refactoring and code generation, visual debugging tools, including memory, registers, and disassembly viewers.

What is MinGW?

MinGW, a contraction of “Minimalist GNU for Windows”, is a port of the GNU Compiler Collection (GCC), and GNU Binutils, for use in the development of native Microsoft Windows applications. Offered in easily installed binary package format, for native deployment on MS-Windows, or user-built from source, for cross-hosted use on Unix or GNU/Linux, the suite exploits Microsoft’s standard system DLLs to provide the C-Runtime and Windows API.

1.  Installation of the Eclipse IDE

Download and install the Eclipse for C++ (CDT) IDE.

  1. Ensure you have the Java SE Runtime Environment (JRE) installed.  The Eclipse IDE requires that the Java JRE or JDK be installed in order to run.
  2. Download the Eclipse CDT IDE.  The downloaded file will have a name similar to: eclipse-cpp-helios-win32.zip
  3. Extract the downloaded file to the following folder:  c:\software
  4. Thus, the full path to the eclipse installation should be: c:\software\eclipse
  5. The Eclipse IDE has an extensive inbuilt help menu with detailed user guides and tutorials.

2.  Installation of the MinGW Compiler Toolchain

Download and install the MinGW Compiler toolchain.  Previously, the various components of the GNU toolchain had to be installed individually and manually.  More recently, we can install the entire MinGW toolchain  in one operation from within the Eclipse IDE.

  1. Within the Eclipse IDE, from the menubar, select:  Help | Install New Software.
  2. Enter in the Wascana repository URL (the latest version may be obtained from here) :   http://svn.codespot.com/a/eclipselabs.org/wascana/repo
  3. Select the packages that appear and follow the on-screen prompts until the installation is complete.  The package displayed may be: Wascana C/C++ Developer for Windows
  4. The MinGW toolchain will be installed at the following location: c:\software\eclipse\mingwStep 2.1 of this article is illustrated in the following figure:
    MinGW Toolchain Installation (Wascana)
  5. Verify the Eclipse C++ IDE and MinGW toolchain are correct installed and configured by following the simple tutorial from the Eclipse IDE Welcome page.
    1. Within the Eclipse IDE, from the menubar, select: Help | Welcome.
    2. Select: Overview | C/C++ Development | C/C++ Development User Guide | Getting Started | Create a simple Application.
    3. Ensure you can complete the tutorial successfully, before proceeding on (Ensure you can successfully build and run the HelloWorld application).

3.  Installation of the Boost C++ Library Sources

Install the Boost C++ Library sources and header files.  The most important reference for the remainder of this article  is the Boost Getting Started on Windows guide.  You should read the guide in parallel with this article.  However, the guide is written with Visual Studio developers in mind.  In this article, we outline the steps for users of the Eclipse IDE with the MinGW compiler toolchain.  At the time of writing, the current version of the Boost C++ library is 1.44.0.  You should always choose to install the latest version.

  1. Download the latest version of the Boost C++ Libraries.
  2. Extract the zip file to the folder:  c:\software
  3. Thus, the full path to the Boost C++ Library installation folder is:  c:\software\boost_1_44_0

4.  Configure the Eclipse C++ projects to use the Boost C++ Library Headers

All Eclipse C++ projects using the Boost libraries must include the Boost C++ Library installation folder in the include paths.

Using the Getting Started on Windows guide, follow the tutorial Build a Simple Program Using Boost.  The example will use a header-only library.  The simple program reads a sequence of integers from standard input, uses Boost.Lambda to multiply each number by three, and writes them to standard output.

  1. Create a new project as previously illustrated in the HelloWorld Tutorial (suggested new project name is BoostLamdaExample1).
  2. Then create a new source file called example.cpp and cut-and-paste the sample source code from the section Build a Simple Program Using Boost of the guide.
  3. Include the Boost C++ Library installation folder in the include paths of the BoostLamdaExample1 project.
    1. Within the Eclipse IDE, within the project explorer on the left-hand-side, select the C++ project using the Boost libraries.
    2. Right-click over the C++ project and select properties from the context menu.
    3. From within the Properties dialog box, insert the full path of the boost C++ Library installation folder into the following:
      1. C/C++ Build | Settings | GCC C++ Compiler | Includes
      1. C/C++ Build | Settings | GCC G Compiler | Includes
        Step 4.3 of this article is illustrated in the following figure:
        Eclipse IDE Boost Include Path
  4. Build the project BoostLamdaExample1. (Ctrl-B)
  5. Verify the Run Configuration is correct.
    1. From the menubar, select Run | Run Configurations.
    2. Select the BoostLamdaExample1 application.
    3. Verify all the parameters appear correct.
      The Run Configuration is illustrated in the following figure:
      BoostLamdaExample1 Run Configuration
  6. Run the project BoostLamdaExample1.
  7. Enter the input data in the console tab: 1 2 3
  8. Input z to exit the program.
  9. If you are able to run the program successfully, then you have built and run a C++ application using a Boost header library.

5.  Compile and build the Boost C++ Binary Libraries

The Boost C++ Libraries come as source code.  Most of the Boost libraries are header-only libraries.  They consist of header files containing templates and inline functions and do not require separately compiled binary libraries or special treatment when linking.  Although most of the libraries consist solely of header files, there are some important binary libraries required and thus, they must be built.

There are prebuilt binaries of the Boost C++ library for Visual Studio (and only Visual Studio) available for free and may be downloaded from:  BoostPro

We are using the Eclipse C++ IDE with MinGW and so we must compile and build the Boost C++ binary libraries ourselves. We will use BjamBjam is the command-line tool that drives the Boost Build system. To build Boost binaries, we invoke bjam from the Boost C++ Library installation folder.  We will first update two batch files to ensure the build process will proceed smoothly.

  1. Set the toolset to GCC.
    1. Edit the file:  c:\software\boost_1_44_0\bootstrap.bat
    2. Replace the following line:
      set toolset=msvc with the line: set toolset=gcc
    3. Save and exit the file.
  2. Update the build batch file with the correct location of the MinGW toolchain (compiler and linker).
    1. Edit the file: c:\software\boost_1_44_0\tools\jam\src\build.bat
    2. Under the procedure :Guess_toolset, update the MinGW entry to point to the correct folder:
      call :Clear_Error
      if EXIST "C:\software\eclipse\mingw\bin\gcc.exe" (
      set "BOOST_JAM_TOOLSET=mingw"
      set "BOOST_JAM_TOOLSET_ROOT=C:\software\eclipse\mingw\"
      goto :eof)
    3. Optionally, remove all other blocks of code similar to the above codeblock from the procedure :Guess_toolset. This is advisable because you may find that the build procedure quickly exits with the error message saying it cannot find the compiler.  Removing all other codeblocks will ensure the compiler and toolset are set correctly.
      The following figure illustrates the complete :Guess_toolset procedure in my version of build.bat.
      GuessToolkit Procedure
  3. Compile and Build the Boost C++ Library binaries from the command prompt.
    1. Open up a command prompt at:   c:\software\boost_1_44_0
    2. Add the MinGW bin folder to the PATH.
      set PATH=c:\software\eclipse\mingw\bin;%PATH%
    3. Optionally, add python to the end of the PATH.  (Obviously, you may need to download and install it).
      set PATH=%PATH%;c:\python27;
    4. Enter the command:
      booststrap

      This should successfully build the executable Bjam.  If not, please review steps 5.1, 5.2 and 5.3.
    5. Build the Boost Library binaries by issuing the following command (This may take over 2hrs to complete):
      bjam --toolset=gcc  --build-dir=c:\software\boost_1_44_0\build  --build-type=complete  stage

      1. The newly built Boost C++ Binary Libraries are generated in the folder: c:\software\boost_1_44_0\stage\lib
      2. The option: --build-type=complete will generate both debug and release builds of the Boost C++ libraries.  This is suitable for developers.
      3. The option: --build-type=minimal will generate release builds only of the Boost C++ libraries.   This may become an issue for developers who want to create debug builds of their projects.  Since the compiler automatically try to link against the debug builds of the Boost C++ Libraries, an error message is displayed.
      4. The declaration of stage or install specifies whether the Boost C++ Libraries are installed in a subfolder named stage or system-wide. The meaning of system-wide depends on the operating system. In Windows, the target directory is c:\boost,  in Linux it is /usr/local. The target directory can also be explicitly specified using the –prefix option.
      5. The intermediate files are generated in the build folder: c:\software\boost_1_44_0\build You may delete the build folder when the entire build process has completed.
      6. If you have a multi-core processor, you can accelerate the build process.  The option: -j N will run up to n shell commands concurrently. The default is 1.  I have an Extreme Quad-Core processor, and adding the option -j 4 reduced the build time from just over 2hrs to just under 40 minutes.

6.  Configure the Eclipse C++ projects to use the Boost C++ Binary Libraries

  1. All Eclipse C++ project using the Boost C++ binary libraries must include the Boost Binary Library folder in the Libraries (-L) settings.
    1. From with the Eclipse IDE, right-click on the selected project and select Properties.
    2. Place the Boost Binary Library folder path  c:\software\boost_1_44_0\stage\lib in the following location:
      C/C++ Build | Settings | MinGW C++ Linker | Libraries | Library search path (-L).
  2. All Eclipse C++ projects using a specific Boost C++ binary library must include the specific binary library in the Libraries (-l) settings.
    1. From with the Eclipse IDE, right-click on the selected project and select Properties.
    2. Place the name of the specific binary library in the following location:
      C/C++ Build | Settings | MinGW C++ Linker | Libraries | Libraries (-l).
    3. IMPORTANT: To link a Boost C++ Binary library, e.g.: libboost_regex-mgw44-1_44.a the command line option should be: -lboost_regex-mgw44-1_44 (i.e.: Remove the prefix lib and the postfix .a).
  3. Step 6 in this article is illustrated in the following figure:
    Boost Binary Library Folder Configuration

7.  Final step – Verify we can use the Boost C++ Binary Libraries from a sample application.

  1. Using the Getting Started on Windows guide, follow the example Link Your Program to a Boost Library.  To demonstrate linking with a Boost binary library, the sample program extracts the subject lines from emails. It uses the Boost.Regex library, which has a separately-compiled binary component.
  2. Create a new C++ project in Eclipse called BoostRegexExample1 and create a new source file called regex.cpp.
  3. Cut-and-paste the sample code from the section Link Your Program to a Boost Library of the guide into regex.cpp.
  4. Add the Boost installation folder to the Include Path of the BoostRegexExample1 project as indicated in step 4.3 of this article.
  5. Add the Boost Library binary folder to the Library (-L) Path of the BoostRegexExample1 project as indicated in step 6.1 of this article.
  6. Add the specific Boost Regex Binary Library boost_regex-mgw44-1_44 to the library (-l) settings as indicated in step 6.2 of this article.
    1. To find the name of a specific library, please browse the Boost Library binary folder, and select the library filename such that it is the shortest filename with the prefix libboost_regex. The similar looking filenames refer to the same library compiled with different options (statically linked, dynamically link, release-build, debug-build, and so on).
  7. Compile and build (Ctrl-B) the project:  BoostRegexExample1.
  8. Verify the Run Configuration parameters are correct:
    1. From the Eclipse IDE menubar, select Run | Run Configurations.
    2. Ensure the BoostRegexExample1 C++ application is selected.
    3. Ensure the Build configuration is set to Debug.
    4. Click Run.
  9. Cut-and-paste the following sample email into the console as input:
    To: Bob
    From: Mary
    Subject: The test is successful
    Body: Great news, Boost Library integration works.
  10. If the following message is printed out, then the program ran successfully (using the Boost Binary Library Regex).
    The test is successful
  11. To exit the program, input Ctrl-Z to the console.
  12. Congratulations! You may now use the Boost Libraries in your C++ application from the Eclipse CDT IDE using the MinGW toolchain.

References

  • Eclipse C++ IDE – Free fully functional C and C++ Integrated Development Environment.
  • Boost C++ Libraries – Free peer-reviewed portable C++ source libraries.
  • MinGW -  Free port of the GNU Compiler Collection (GCC), and GNU Binutils, for use in the development of native Microsoft Windows applications.
  • Wascana - Wascana is the Eclipse C/C++ IDE for the Windows along with the MinGW GNU toolchain.
  • LearnCpp.com – Free website devoted to teaching you to program in C++.
  • Online C++ Cookbook. – Excellent resource for Java, C++, C#, Oracle and SQL developers.
  • The Boost C++ Libraries Book – An online book providing an overview on using the Boost C++ libraries.  The book is released under a Creative Commons License.
  • cdtdoug.blogspot.com – Personal blog of the Eclipse CDT project  leader providing insights into his mind and the future directions of the project.
About these ads

17 comments

  1. I seemed to be aware about this previously, nevertheless there was clearly a few helpful bits that concluded the picture for me personally, thank you so much!


  2. Section 5.2.1 for Boost 1.46: “C:\software\boost_1_46_0\tools\build\v2\engine\src\build.bat”.
    Great article! Thanks a lot.


  3. Thanks for this article! I’m trying to do this for the Boost_1_46_1 build, and when I run the bootstrap batch file (which ran dandily building the Visual C libraries!) I get a “This program can’t start because mspdb100.dll is missing from your computer. Try reinstalling the program to fix this problem.” Joy! (Any tips?) And as Adriano writes, the build.bat file has moved.

    I’ve just subscribed to the Boost.Build mailing list to see if I can start hunting down this problem.


    • Thanks a lot, helped me after hours of futile attempts linking against boost.

      # IMPORTANT: To link a Boost C++ Binary library, e.g.: libboost_regex-mgw44-1_44.a the command line option should be: -lboost_regex-mgw44-1_44 (i.e.: Remove the prefix lib and the postfix .a).


  4. Thanks in advance,

    I found the problem that I can not input into the console at the step 7.8. Could you please help me one more.

    Thanks.


  5. I just installed Boost 1.48, and I found this guide invaluable (had to make a few minor tweaks). I followed from step 4.
    Step 5.1 (edit bootstrap.bat): I also had to add the argument “mingw” after “call.\build.bat”
    Step 5.2 (edit build.bat): It is now in \tools\build\v2\engine.
    Step 5.3.5 (build binaries): The bootstrap told me to type “.\b2″ and this seemed to suffice; I did not do the line command shown here but it all seems to work (took about 15 minutes).
    Many thanks!


  6. Thank You! You save me lot’s of time!
    Don’t you want to do the same to POCO C++; ITK and VTK :)

    Great Job and Thank You Again!


  7. Thank you so much for this explanation.i followed it to install and build boost 1.48.0 .i had the problem that eclipse was terminated once i run the program.i fixed this problem by putting the directory of the binary libraries in my system environment variables.


    • I followed every step and kept getting this message that the library could not be found. Adding the directory of the binary files to my PATH solved it. Thanks!!


  8. Nice but it should be:

    call :Clear_Error
    if EXIST “C:\software\eclipse\mingw\bin\gcc.exe” (
    set “BOOST_JAM_TOOLSET=mingw”
    set “BOOST_JAM_TOOLSET_ROOT=C:\software\eclipse\mingw\”
    )
    goto :eof


  9. Hey! Brilliant guide! Thank you so much :)
    But I am stuck.. The thing is my Eclipse on Project Build is not generating a binary. So, obviously it cannot run the application.. Also to be noted is that, this is using only the Boost header files. Not the Binaries! So what do I do?! Please help me!


  10. Magnificent beat ! I wish to apprentice even as you amend your site, how could i
    subscribe for a blog site? The account helped me a applicable deal.

    I had been a little bit acquainted of this your broadcast provided vibrant clear idea


  11. The step 2. Installation of the MinGW Compiler Toolchain is outdated.
    It seems like wascana is no longer supported : http://www.eclipse.org/forums/index.php/t/370479/


  12. I’m having a problem. Section 1-6 went just fine. Now, I am getting a back executable from section 7. I’m getting a “procedure entry point _ZNSt16invalid_argumentD2Ev could not be located in the dynamic link library libstdc++-6.dll” when I run the executable. I am using the source as you directed from the Getting Started. I have the following versions:

    Eclipse Kepler
    Mingw 4.5.2.2
    Boost_1_54_0

    Do you know why this might be happening?


  13. Refinance is done used consolidation student loanss.
    The majority of this calculator tools will
    only work out the basic details of the company should be replaced.
    Bsasically the car should not be an option
    and you also have to lower your rates over time. People with many credit cards should pay down the balances where people with good credit.


  14. The majority of home-made treatments have been verified, some individuals are found embarrassed along with them.
    You’re in a ship, you just aren’t out of luck. Additionally applying home remedies, essential locate and easily buy
    group of over-the-counter wart taking out solutions and products.
    Over-the-counter wart fading appliances are time and again accessible to down below 40 $ $
    $ $. Them are available online, so in very scale and as well , home improvement stores.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: