Difference between revisions of "BoostWindowsQuickRef"

From Code::Blocks
(Updated for Boost 1.36.0)
Line 62: Line 62:
 
* #include <boost/*.hpp> in your source file
 
* #include <boost/*.hpp> in your source file
 
* In your project's build options, highlight the root of your project, select the "Linker settings" tab, and add "boost_*-mgw34-mt-1_36" to your Link libraries
 
* In your project's build options, highlight the root of your project, select the "Linker settings" tab, and add "boost_*-mgw34-mt-1_36" to your Link libraries
For examle, use "#include <boost/filesystem.hpp>" and "boost_filesystem-mgw34-mt-1_36" to use boost.filesystem.
+
For examle, use "#include <boost/filesystem.hpp>", "boost_filesystem-mgw34-mt-1_36" and "boost_system-mgw34-mt-1_36" to use boost.filesystem.
  
 
== Frequently Asked Questions ==
 
== Frequently Asked Questions ==
  
 
No Frequently Asked Questions (or Frequently Given Answers) have been entered yet.
 
No Frequently Asked Questions (or Frequently Given Answers) have been entered yet.

Revision as of 11:52, 31 October 2008

A beginner's quick reference for setting up Boost with Code::Blocks in Windows
Supported compilers: MinGW or MSVC


Important Requirements:

  • Windows compiler - You need to have correctly installed the free MinGW/GCC compiler or one of Microsoft's compilers (the Express editions are free, but you must also install the Platform SDK). The latest stable release of Code::Blocks includes a MinGW-bundled version which includes all necessary packages; or, if you install it by hand, you need at least the gcc-core, gcc-g++, binutils, w32api, and mingw32-make packages. Also, ensure that the folder containing the compiler executables (typically C:\Program Files\CodeBlocks\bin) is in your Windows PATH environment variable.
  • Recent version of Code::Blocks - You need to have successfully installed and run a recent version of Code::Blocks -- either the latest stable release or [/index.php/board,20.0.html a recent nightly build].


Download Boost

You can download the Boost source code and compile it yourself, or, only if you are using MSVC 2003 (7.1) or later, you can use a web-based installer to download pre-built libraries.

Boost Source Code

The Boost libraries are distributed as source code archived in .7z, .tar.bz2, .tar.gz, or .zip format; choose whichever archive format is easiest for you to unpack. The current stable release of Boost is 1.36.0. Click here to browse the Boost 1.36.0 downloadable files. You can check the Boost download page to see if a newer stable version is available.

You also need to download Boost Jam in order to build Boost. The current stable release of Boost Jam is 3.1.16. Click here to download Boost Jam for Windows (boost-jam-3.1.16-1-ntx86.zip; 115 KB).

It is highly recommended that you unpack the sources to a path without spaces. You should choose a volume with at least XXX MB of free space. Typically, the Boost sources and Boost Jam are unpacked in separate locations, ending up with "<path>\boost_1_36_0" and "<path>\boost-jam-3.1.16-1-ntx86".

Boost Installer for MSVC 2003 (7.1) or later

BoostPro Computing distributes a free web-based installer that will download and install prebuilt versions of the Boost libraries for MSVC. Click here to browse the BoostPro Free Downloads. The amount of space used by the installation varies depending on which libraries and variants you choose.


Build Boost

This step is unnecessary if you are using the BoostPro installer

  • Open up a command prompt for building. If you are using MinGW/GCC, simply use the standard Windows command shell (open the Start menu, click "Run...", enter "cmd" and hit OK). If you are using MSVC, you should use the special command shell which sets up the correct environment variables for you. If you use a version of MSVC which required you to download the Platform SDK separately, ensure that whichever command environment you use includes the Platform SDK tools and paths as well as the standard compiler tools and paths.
  • Ensure that Boost Jam is in the PATH environment variable (where <path> is the path you unpacked Boost Jam to):
set PATH=<path>\boost-jam-3.1.16-1-ntx86;%PATH%
  • Change to the Boost sources directory (where <path> is the path you unpacked the Boost sources to):
cd <path>\boost_1_36_0
  • Execute the build command. The recommended command to use for MinGW/GCC is (where <installpath> is where you want the Boost headers and libraries; typically C:\Program Files\CodeBlocks):
bjam --toolset=gcc "--prefix=<installpath>" install
  • The recommended command to use for MSVC is (where <installpath> is where you want the Boost headers and libraries):
bjam --toolset=msvc "--prefix=<installpath>" install
  • This step will generally take 5-20 minutes, depending on the capabilities of your PC.
  • The above commands will build release, multithreaded, DLL versions of the Boost libraries. If you want other variants, add --build-type=complete to the command line. This will take a much longer amount of time to build.


Add Boost to an existing project in Code::Blocks

The Boost libraries are usable in nearly any Code::Blocks project. You can create a new project that will use Boost or open an existing project. With your project open, perform these steps.

Set up a Code::Blocks global variable for Boost

This step only needs to be performed once, after which the global variable you've created will be available for any project.

  • Open the Settings menu and select "Global variables..."
  • Click the "New" button next to the Current variable list, specify a name like "boost", and hit OK
  • In the "base" field of the Builtin fields section, browse for the base of your Boost installation -- the path you specified in the --prefix option of the build command
  • In the "include" field, browse for the "include\boost-1_36" subfolder of your Boost installation -- it should be the path in the "base" field with "\include\boost-1_36" tacked on.
  • Hit the Close button to save your global variable

Add Boost search directories to your project

  • Right-click your project's name in the Projects section of the Management window and select "Build options..."
  • Highlight the root of your project in the tree on the left side of the Project build options window
  • Select the "Search directories" tab
  • With the "Compiler" subtab selected, click the Add button, enter "$(#boost.include)" (without the quotes), and hit OK

If you are using the bundled version of MinGW with Code::Blocks, and you used your C::B installation in the --prefix option as recommended, the following step is unnecessary

  • With the "Linker" subtab selected, click the Add button, enter "$(#boost.lib)" (without the quotes), and hit OK

Include Boost headers and link with Boost libraries

Your project is now ready to use the Boost libraries. For each library you want to use, do the following:

  • #include <boost/*.hpp> in your source file
  • In your project's build options, highlight the root of your project, select the "Linker settings" tab, and add "boost_*-mgw34-mt-1_36" to your Link libraries

For examle, use "#include <boost/filesystem.hpp>", "boost_filesystem-mgw34-mt-1_36" and "boost_system-mgw34-mt-1_36" to use boost.filesystem.

Frequently Asked Questions

No Frequently Asked Questions (or Frequently Given Answers) have been entered yet.