mirror of
https://github.com/boostorg/more.git
synced 2024-12-25 23:20:12 +08:00
Factored getting started guide into separate windows and *nix documents
[SVN r36493]
This commit is contained in:
parent
30237aa618
commit
3c82e58140
File diff suppressed because it is too large
Load Diff
1042
getting_started.rst
1042
getting_started.rst
File diff suppressed because it is too large
Load Diff
23
getting_started/Jamfile.v2
Normal file
23
getting_started/Jamfile.v2
Normal file
@ -0,0 +1,23 @@
|
||||
# Copyright David Abrahams 2006. Distributed under the Boost
|
||||
# Software License, Version 1.0. (See accompanying
|
||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
import docutils ;
|
||||
|
||||
import path ;
|
||||
sources = [ path.glob . : *.rst ] ;
|
||||
bases = $(sources:S=) ;
|
||||
|
||||
# This is a path relative to the html/ subdirectory where the
|
||||
# generated output will eventually be moved.
|
||||
stylesheet = "--stylesheet=../../rst.css" ;
|
||||
|
||||
for local b in $(bases)
|
||||
{
|
||||
html $(b) : $(b).rst :
|
||||
|
||||
<docutils-html>"--link-stylesheet --traceback --trim-footnote-reference-space --footnote-references=superscript "$(stylesheet)
|
||||
;
|
||||
}
|
||||
|
||||
alias htmls : $(bases) ;
|
||||
stage . : $(bases) ;
|
10
getting_started/detail/binary-head.rst
Normal file
10
getting_started/detail/binary-head.rst
Normal file
@ -0,0 +1,10 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
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.
|
||||
|
123
getting_started/detail/build-from-source-head.rst
Normal file
123
getting_started/detail/build-from-source-head.rst
Normal file
@ -0,0 +1,123 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
Boost.Build_ is a text-based system for developing, testing, and
|
||||
installing software. To use it, you'll need an executable called
|
||||
``bjam``.
|
||||
|
||||
.. |precompiled-bjam| replace:: pre-compiled ``bjam`` executables
|
||||
|
||||
|
||||
.. _precompiled-bjam: http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=72941
|
||||
.. _Boost.Jam documentation: Boost.Jam_
|
||||
.. _Boost.Build: ../../tools/build/index.html
|
||||
.. _Boost.Jam: ../../tools/jam/index.html
|
||||
.. _Boost.Build documentation: Boost.Build_
|
||||
|
||||
Get ``bjam``
|
||||
............
|
||||
|
||||
``bjam`` is the |command-line tool| that drives the Boost Build
|
||||
system. To build Boost binaries, you'll invoke ``bjam`` from the
|
||||
Boost root.
|
||||
|
||||
Boost provides |precompiled-bjam|_ for a variety of platforms.
|
||||
Alternatively, you can build ``bjam`` yourself using `these
|
||||
instructions`__.
|
||||
|
||||
__ ../../doc/html/jam/building.html
|
||||
|
||||
|
||||
.. _toolset:
|
||||
.. _toolset-name:
|
||||
|
||||
Identify Your Toolset
|
||||
.....................
|
||||
|
||||
First, find the toolset corresponding to your compiler in the
|
||||
following table.
|
||||
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|Toolset |Vendor |Notes |
|
||||
|Name | | |
|
||||
+===========+====================+=============================+
|
||||
|``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|
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|``cw`` |Metrowerks/FreeScale|The CodeWarrior compiler. We|
|
||||
| | |have not tested versions of |
|
||||
| | |this compiler produced since |
|
||||
| | |it was sold to FreeScale. |
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|``dmc`` |Digital Mars |As of this Boost release, no |
|
||||
| | |version of dmc is known to |
|
||||
| | |handle Boost well. |
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|``darwin`` |Apple Computer |Apple's version of the GCC |
|
||||
| | |toolchain with support for |
|
||||
| | |Darwin and MacOS X features |
|
||||
| | |such as frameworks. |
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|``gcc`` |The Gnu Project |Includes support for Cygwin |
|
||||
| | |and MinGW compilers. |
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|``hp_cxx`` |Hewlett Packard |Targeted at the Tru64 |
|
||||
| | |operating system. |
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|``intel`` |Intel | |
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|``kylix`` |Borland | |
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|``msvc`` |Microsoft | |
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|``qcc`` |QNX Software Systems| |
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|``sun`` |Sun |Only very recent versions are|
|
||||
| | |known to work well with |
|
||||
| | |Boost. |
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|``vacpp`` |IBM |The VisualAge C++ compiler. |
|
||||
+-----------+--------------------+-----------------------------+
|
||||
|
||||
__ Boost.Build_
|
||||
|
||||
If you have multiple versions of a particular compiler installed,
|
||||
you can append the version number to the toolset name, preceded by a
|
||||
hyphen, e.g. ``msvc-7.1`` or ``gcc-3.4``.
|
||||
|
||||
.. Note:: if you built ``bjam`` yourself, you may
|
||||
have selected a toolset name for that purpose, but that does not
|
||||
affect this step in any way; you still need to select a Boost.Build
|
||||
toolset from the table.
|
||||
|
||||
.. _build directory:
|
||||
.. _build-directory:
|
||||
|
||||
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.
|
||||
|
||||
Invoke ``bjam``
|
||||
...............
|
||||
|
||||
.. |build-directory| replace:: *build-directory*
|
||||
.. |toolset-name| replace:: *toolset-name*
|
||||
|
||||
Change your current directory to the Boost root directory and
|
||||
invoke ``bjam`` as follows:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
bjam **--build-dir=**\ |build-directory|_ **--toolset=**\ |toolset-name|_ stage
|
66
getting_started/detail/build-from-source-tail.rst
Normal file
66
getting_started/detail/build-from-source-tail.rst
Normal file
@ -0,0 +1,66 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
Boost.Build will place the Boost binaries in the ``stage``\ |/|
|
||||
subdirectory of your `build directory`_.
|
||||
|
||||
.. Note:: ``bjam`` 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
|
||||
``bjam``, type::
|
||||
|
||||
bjam --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.
|
||||
|
||||
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:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
*toolset-name*.c++ *long*\ /\ *path*\ /\ *to*\ /\ *file*\ /\ *being*\ /\ *built*
|
||||
|
||||
* Compiler warnings.
|
||||
|
||||
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.
|
||||
|
||||
__ ../../libs/iostreams/doc/installation.html
|
||||
|
||||
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
|
||||
in the `Boost.Build documentation`_. 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.Build mailing list`_.
|
||||
|
28
getting_started/detail/build-simple-head.rst
Normal file
28
getting_started/detail/build-simple-head.rst
Normal file
@ -0,0 +1,28 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
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``.
|
||||
|
26
getting_started/detail/common-footnotes.rst
Normal file
26
getting_started/detail/common-footnotes.rst
Normal file
@ -0,0 +1,26 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
.. [#warnings] 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.
|
||||
|
||||
.. [#distinct] 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.
|
||||
|
||||
.. [#debug-abi] These libraries were compiled without optimization
|
||||
or inlining, with full debug symbols enabled, and without
|
||||
``NDEBUG`` ``#define``\ d. All though 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.
|
||||
|
||||
.. [#native] This feature of STLPort is deprecated because it's
|
||||
impossible to make it work transparently to the user; we don't
|
||||
recommend it.
|
||||
|
21
getting_started/detail/common-unix.rst
Normal file
21
getting_started/detail/common-unix.rst
Normal file
@ -0,0 +1,21 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
.. |//| replace:: **/**
|
||||
.. |/| replace:: ``/``
|
||||
|
||||
.. |default-root| replace:: ``/usr/local/``\ |boost_ver|
|
||||
.. |default-root-bold| replace:: **/usr/local/**\ |boost_ver-bold|
|
||||
|
||||
.. |root| replace:: *path/to/*\ |boost_ver|
|
||||
|
||||
.. |forward-slashes| replace:: `` ``
|
||||
|
||||
.. |precompiled-dir| replace:: `` ``
|
||||
|
||||
.. |include-paths| replace:: `` ``
|
||||
|
||||
.. |command-line tool| replace:: command-line tool
|
||||
|
||||
.. include:: common.rst
|
29
getting_started/detail/common-windows.rst
Normal file
29
getting_started/detail/common-windows.rst
Normal file
@ -0,0 +1,29 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
.. |//| replace:: **\\**
|
||||
.. |/| replace:: ``\``
|
||||
|
||||
.. |default-root| replace:: ``C:\Program Files\boost\``\ |boost_ver|
|
||||
.. |default-root-bold| replace:: **C:\\Program Files\\boost\\**\ |boost_ver-bold|
|
||||
|
||||
.. |root| replace:: *path\\to\\*\ |boost_ver|
|
||||
|
||||
.. |include-paths| replace:: 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.
|
||||
|
||||
.. |forward-slashes| replace:: Even Windows users can (and, for
|
||||
portability reasons, probably should) use forward slashes in
|
||||
``#include`` directives; your compiler doesn't care.
|
||||
|
||||
.. |precompiled-dir| replace::
|
||||
|
||||
**lib**\ |//| .....................\ *precompiled library binaries*
|
||||
|
||||
|
||||
.. |command-line tool| replace:: `command-line tool`_
|
||||
|
||||
.. include:: common.rst
|
5
getting_started/detail/common.rst
Normal file
5
getting_started/detail/common.rst
Normal file
@ -0,0 +1,5 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
.. |next| replace:: *skip to the next step*
|
39
getting_started/detail/conclusion.rst
Normal file
39
getting_started/detail/conclusion.rst
Normal file
@ -0,0 +1,39 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
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.Jam reference manual`_
|
||||
* `Boost Users' mailing list`_
|
||||
* `Boost.Build mailing list`_
|
||||
* `Boost.Build Wiki`_
|
||||
* `Index of all Boost library documentation`_
|
||||
|
||||
.. _Index of all Boost library documentation: ../../libs/index.html
|
||||
|
||||
.. Admonition:: Onward
|
||||
|
||||
.. epigraph::
|
||||
|
||||
Good luck, and have fun!
|
||||
|
||||
-- the Boost Developers
|
||||
|
||||
.. _Boost.Build reference manual: ../tools/build/v2
|
||||
.. _Boost.Jam reference manual: `Boost.Jam`_
|
||||
.. _Boost Users' mailing list: ../../more/mailing_lists.htm#users
|
||||
.. _Boost.Build Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Boost.Build_V2
|
||||
.. _Boost.Build mailing list: ../../more/mailing_lists.htm#jamboost
|
||||
|
88
getting_started/detail/distro.rst
Normal file
88
getting_started/detail/distro.rst
Normal file
@ -0,0 +1,88 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
The Boost Distribution
|
||||
======================
|
||||
|
||||
This is is a sketch of the directory structure you'll end up with:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
|boost_ver-bold|\ |//| .................\ *The “boost root directory”*
|
||||
**index.htm** .........\ *A copy of www.boost.org starts here*
|
||||
**boost**\ |//| .........................\ *All Boost Header files*
|
||||
|precompiled-dir|
|
||||
**libs**\ |//| ............\ *Tests, .cpp*\ s\ *, docs, etc., by library*
|
||||
**index.html** ........\ *Library documentation starts here*
|
||||
**algorithm**\ |//|
|
||||
**any**\ |//|
|
||||
**array**\ |//|
|
||||
*…more libraries…*
|
||||
**status**\ |//| .........................\ *Boost-wide test suite*
|
||||
**tools**\ |//| ...........\ *Utilities, e.g. bjam, quickbook, bcp*
|
||||
**more**\ |//| ..........................\ *Policy documents, etc.*
|
||||
**doc**\ |//| ...............\ *A subset of all Boost library docs*
|
||||
|
||||
.. sidebar:: Header Organization
|
||||
|
||||
.. class:: pre-wrap
|
||||
|
||||
The organization of Boost library headers isn't entirely uniform,
|
||||
but most libraries follow a few patterns:
|
||||
|
||||
* Some older libraries and most very small libraries place all
|
||||
public headers directly into ``boost``\ |/|.
|
||||
|
||||
* Most libraries' public headers live in a subdirectory of
|
||||
``boost``\ |/|, named after the library. For example, you'll find
|
||||
the Python library's ``def.hpp`` header in
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
``boost``\ |/|\ ``python``\ |/|\ ``def.hpp``.
|
||||
|
||||
* Some libraries have an “aggregate header” in ``boost``\ |/| that
|
||||
``#include``\ s all of the library's other headers. For
|
||||
example, Boost.Python_'s aggregate header is
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
``boost``\ |/|\ ``python.hpp``.
|
||||
|
||||
* Most libraries place private headers in a subdirectory called
|
||||
``detail``\ |/|, or ``aux_``\ |/|. Don't expect to find
|
||||
anything you can use in these directories.
|
||||
|
||||
It's important to note the following:
|
||||
|
||||
.. _Boost root directory:
|
||||
|
||||
1. The path to the **boost root directory** (often |default-root|) is
|
||||
sometimes referred to as ``$BOOST_ROOT`` in documentation and
|
||||
mailing lists .
|
||||
|
||||
2. To compile anything in Boost, you need a directory containing
|
||||
the ``boost``\ |/| subdirectory in your ``#include`` path. |include-paths|
|
||||
|
||||
3. 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:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
#include <boost/\ *whatever*\ .hpp>
|
||||
|
||||
or
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
#include "boost/\ *whatever*\ .hpp"
|
||||
|
||||
depending on your religion as regards the use of angle bracket
|
||||
includes. |forward-slashes|
|
||||
|
||||
4. Don't be distracted by the ``doc``\ |/| subdirectory; it only
|
||||
contains a subset of the Boost documentation. Start with
|
||||
``libs``\ |/|\ ``index.html`` if you're looking for the whole enchilada.
|
||||
|
16
getting_started/detail/errors-and-warnings.rst
Normal file
16
getting_started/detail/errors-and-warnings.rst
Normal file
@ -0,0 +1,16 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
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. [#warnings]_ **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`_.
|
||||
|
||||
__ `Build a Simple Program Using Boost`_
|
||||
|
45
getting_started/detail/header-only.rst
Normal file
45
getting_started/detail/header-only.rst
Normal file
@ -0,0 +1,45 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
Header-Only Libraries
|
||||
=====================
|
||||
|
||||
The first thing many people want to know is, “how do I build
|
||||
Boost?” The good news is that often, there's nothing to build.
|
||||
|
||||
.. admonition:: Nothing to Build?
|
||||
|
||||
Most Boost libraries are **header-only**: they consist *entirely
|
||||
of header files* containing templates and inline functions, and
|
||||
require no separately-compiled library binaries or special
|
||||
treatment when linking.
|
||||
|
||||
.. _separate:
|
||||
|
||||
The only Boost libraries that *must* be built separately are:
|
||||
|
||||
* Boost.Filesystem_
|
||||
* Boost.IOStreams_
|
||||
* Boost.ProgramOptions_
|
||||
* Boost.Python_
|
||||
* Boost.Regex_
|
||||
* Boost.Serialization_
|
||||
* Boost.Signals_
|
||||
* Boost.Thread_
|
||||
* Boost.Wave_
|
||||
|
||||
A few libraries have optional separately-compiled binaries:
|
||||
|
||||
* Boost.DateTime_ has a binary component that is only needed if
|
||||
you're using its ``to_string``\ /\ ``from_string`` or serialization
|
||||
features, or if you're targeting Visual C++ 6.x or Borland.
|
||||
|
||||
* Boost.Graph_ also has a binary component that is only needed if
|
||||
you intend to `parse GraphViz files`__.
|
||||
|
||||
* Boost.Test_ can be used in “header-only” or “separately compiled”
|
||||
mode, although **separate compilation is recommended for serious
|
||||
use**.
|
||||
|
||||
__ ../../libs/graph/doc/read_graphviz.html
|
80
getting_started/detail/library-naming.rst
Normal file
80
getting_started/detail/library-naming.rst
Normal file
@ -0,0 +1,80 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
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-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. [#distinct]_
|
||||
|
||||
``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: |
|
||||
+=====+==============================================================================+
|
||||
|``s``|linking statically to the C++ standard library and compiler runtime support |
|
||||
| |libraries. |
|
||||
+-----+------------------------------------------------------------------------------+
|
||||
|``g``|using debug versions of the standard and runtime support libraries. |
|
||||
+-----+------------------------------------------------------------------------------+
|
||||
|``y``|using a special `debug build of Python`__. |
|
||||
+-----+------------------------------------------------------------------------------+
|
||||
|``d``|building a debug version of your code. [#debug-abi]_ |
|
||||
+-----+------------------------------------------------------------------------------+
|
||||
|``p``|using the STLPort standard library rather than the default one supplied with |
|
||||
| |your compiler. |
|
||||
+-----+------------------------------------------------------------------------------+
|
||||
|``n``|using STLPort's deprecated “native iostreams” feature. [#native]_ |
|
||||
+-----+------------------------------------------------------------------------------+
|
||||
|
||||
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 in “native iostreams” mode,
|
||||
the tag would be: ``-sgdpn``. If none of the above apply, the
|
||||
ABI tag is ommitted.
|
||||
|
||||
``-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 \*nix platforms the extensions are ``.a``
|
||||
and ``.so`` for static libraries (archives) and shared libraries,
|
||||
respectively. On Windows, ``.dll`` indicates a shared library
|
||||
and—except for static libraries built by ``gcc`` toolset, whose
|
||||
names always end in ``.a``— ``.lib`` indicates a static or import
|
||||
library. Where supported by \*nix toolsets, 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.
|
||||
|
||||
.. _Boost.Build toolset names: toolset-name_
|
||||
|
||||
__ ../../libs/python/doc/building.html#variants
|
||||
|
39
getting_started/detail/link-head.rst
Normal file
39
getting_started/detail/link-head.rst
Normal file
@ -0,0 +1,39 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
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:
|
||||
|
||||
1. Tool configuration, e.g. choosing command-line options or IDE
|
||||
build settings.
|
||||
|
||||
2. Identifying the library binary, among all the build variants,
|
||||
whose compile configuration is compatible with the rest of your
|
||||
project.
|
||||
|
16
getting_started/detail/links.rst
Normal file
16
getting_started/detail/links.rst
Normal file
@ -0,0 +1,16 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
.. _Boost.DateTime: ../../libs/date_time/index.html
|
||||
.. _Boost.Filesystem: ../../libs/filesystem/index.html
|
||||
.. _Boost.Graph: ../../libs/graph/index.html
|
||||
.. _Boost.IOStreams: ../../libs/iostreams/index.html
|
||||
.. _Boost.ProgramOptions: ../../libs/program_options/index.html
|
||||
.. _Boost.Python: ../../libs/python/doc/building.html
|
||||
.. _Boost.Regex: ../../libs/regex/index.html
|
||||
.. _Boost.Serialization: ../../libs/serialization/index.html
|
||||
.. _Boost.Signals: ../../libs/signals/index.html
|
||||
.. _Boost.Test: ../../libs/test/index.html
|
||||
.. _Boost.Thread: ../../libs/thread/index.html
|
||||
.. _Boost.Wave: ../../libs/wave/index.html
|
12
getting_started/detail/release-variables.rst
Normal file
12
getting_started/detail/release-variables.rst
Normal file
@ -0,0 +1,12 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
.. This file contains all the definitions that need to be updated
|
||||
.. for each new release of Boost.
|
||||
|
||||
.. |boost-version-number| replace:: 1.34.0
|
||||
.. |boost_ver| replace:: ``boost_1_34_0``
|
||||
.. |boost_ver-bold| replace:: **boost_1_34_0**
|
||||
|
||||
.. _sf-download: http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041&release_id=376197
|
16
getting_started/detail/test-head.rst
Normal file
16
getting_started/detail/test-head.rst
Normal file
@ -0,0 +1,16 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
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.
|
||||
|
58
getting_started/index.html
Normal file
58
getting_started/index.html
Normal file
@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
|
||||
<title>Boost Getting Started</title>
|
||||
<link rel="stylesheet" href="../../rst.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="logo-getting-started">
|
||||
<h1 class="title"><a class="reference" href="../../index.htm"><img alt="Boost" class="boost-logo" src="../../boost.png" /></a> Getting Started</h1>
|
||||
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<div class="section">
|
||||
<h1><a id="welcome" name="welcome">Welcome</a></h1>
|
||||
<p>Welcome to the Boost libraries! By the time you've completed this
|
||||
tutorial, you'll be at least somewhat comfortable with the contents
|
||||
of a Boost distribution and how to go about using it.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="what-s-here" name="what-s-here">What's Here</a></h1>
|
||||
<p>This document is designed to be an <em>extremely</em> gentle introduction,
|
||||
so we included a fair amount of material that may already be very
|
||||
familiar to you. To keep things simple, we also left out some
|
||||
information intermediate and advanced users will probably want. At
|
||||
the end of this document, we'll refer you on to resources that can
|
||||
help you pursue these topics further.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="preliminaries" name="preliminaries">Preliminaries</a></h1>
|
||||
<p>We use one typographic convention that might not be immediately
|
||||
obvious: <em>italic</em> text in examples is meant as a descriptive
|
||||
placeholder for something else, usually information that you'll
|
||||
provide. For example:</p>
|
||||
<pre class="literal-block">
|
||||
<strong>$</strong> echo "My name is <em>your name</em>"
|
||||
</pre>
|
||||
<p>Here you're expected to imagine replacing the text “your name” with
|
||||
your actual name.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a id="ready" name="ready">Ready?</a></h1>
|
||||
<p>Let's go!</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<hr class="footer" />
|
||||
<div class="nextpage line-block">
|
||||
<div class="line"><strong>Next:</strong> <a class="reference" href="windows.html">Getting Started on Microsoft Windows</a></div>
|
||||
<div class="line"><strong>or:</strong> <a class="reference" href="unix-variants.html">Getting Started on Unix variants (e.g. Linux, MacOS)</a></div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
60
getting_started/index.rst
Normal file
60
getting_started/index.rst
Normal file
@ -0,0 +1,60 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
============================
|
||||
|(logo)|__ Getting Started
|
||||
============================
|
||||
|
||||
.. |(logo)| image:: ../../boost.png
|
||||
:alt: Boost
|
||||
:class: boost-logo
|
||||
|
||||
__ ../../index.htm
|
||||
|
||||
Welcome
|
||||
-------
|
||||
|
||||
Welcome to the Boost libraries! By the time you've completed this
|
||||
tutorial, you'll be at least somewhat comfortable with the contents
|
||||
of a Boost distribution and how to go about using it.
|
||||
|
||||
What's Here
|
||||
-----------
|
||||
|
||||
This document is designed to be an *extremely* gentle introduction,
|
||||
so we included a fair amount of material that may already be very
|
||||
familiar to you. To keep things simple, we also left out some
|
||||
information intermediate and advanced users will probably want. At
|
||||
the end of this document, we'll refer you on to resources that can
|
||||
help you pursue these topics further.
|
||||
|
||||
Preliminaries
|
||||
-------------
|
||||
|
||||
We use one typographic convention that might not be immediately
|
||||
obvious: *italic* text in examples is meant as a descriptive
|
||||
placeholder for something else, usually information that you'll
|
||||
provide. For example:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
**$** echo "My name is *your name*\ "
|
||||
|
||||
Here you're expected to imagine replacing the text “your name” with
|
||||
your actual name.
|
||||
|
||||
Ready?
|
||||
------
|
||||
|
||||
Let's go!
|
||||
|
||||
.. footer::
|
||||
.. class:: nextpage
|
||||
|
||||
| **Next:** `Getting Started on Microsoft Windows`__
|
||||
| **or:** `Getting Started on Unix variants (e.g. Linux, MacOS)`__
|
||||
|
||||
__ windows.html
|
||||
__ unix-variants.html
|
||||
|
786
getting_started/unix-variants.html
Normal file
786
getting_started/unix-variants.html
Normal file
@ -0,0 +1,786 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
|
||||
<title>Boost Getting Started on Unix Variants</title>
|
||||
<meta content="Getting Started with Boost on Unix Variants (including Linux and MacOS)" name="description" />
|
||||
<link rel="stylesheet" href="../../rst.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="logo-getting-started-on-unix-variants">
|
||||
<h1 class="title"><a class="reference" href="../../index.htm"><img alt="Boost" class="boost-logo" src="../../boost.png" /></a> Getting Started on Unix Variants</h1>
|
||||
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<!-- maybe we don't need this
|
||||
.. Admonition:: A note to Cygwin_ and MinGW_ users
|
||||
|
||||
If you plan to build from the Cygwin_ bash shell, you're in the
|
||||
right place. If you plan to use your tools from the Windows
|
||||
command prompt, you should follow the instructions for `getting
|
||||
started on Windows`_. Other command shells, such as MinGW_\ 's
|
||||
MSYS, are not supported—they may or may not work.
|
||||
|
||||
.. _`Getting Started on Windows`: windows.html
|
||||
.. _Cygwin: http://www.cygwin.com
|
||||
.. _MinGW: http://mingw.org -->
|
||||
<div class="contents topic">
|
||||
<p class="topic-title first"><a id="index" name="index">Index</a></p>
|
||||
<ul class="auto-toc simple">
|
||||
<li><a class="reference" href="#get-boost" id="id17" name="id17">1 Get Boost</a></li>
|
||||
<li><a class="reference" href="#the-boost-distribution" id="id18" name="id18">2 The Boost Distribution</a></li>
|
||||
<li><a class="reference" href="#header-only-libraries" id="id19" name="id19">3 Header-Only Libraries</a></li>
|
||||
<li><a class="reference" href="#build-a-simple-program-using-boost" id="id20" name="id20">4 Build a Simple Program Using Boost</a><ul class="auto-toc">
|
||||
<li><a class="reference" href="#errors-and-warnings" id="id21" name="id21">4.1 Errors and Warnings</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#prepare-to-use-a-boost-library-binary" id="id22" name="id22">5 Prepare to Use a Boost Library Binary</a><ul class="auto-toc">
|
||||
<li><a class="reference" href="#easy-build-and-install" id="id23" name="id23">5.1 Easy Build and Install</a></li>
|
||||
<li><a class="reference" href="#or-custom-build-and-install" id="id24" name="id24">5.2 Or, Custom Build and Install</a><ul class="auto-toc">
|
||||
<li><a class="reference" href="#get-bjam" id="id25" name="id25">5.2.1 Get <tt class="docutils literal"><span class="pre">bjam</span></tt></a></li>
|
||||
<li><a class="reference" href="#identify-your-toolset" id="id26" name="id26">5.2.2 Identify Your Toolset</a></li>
|
||||
<li><a class="reference" href="#select-a-build-directory" id="id27" name="id27">5.2.3 Select a Build Directory</a></li>
|
||||
<li><a class="reference" href="#invoke-bjam" id="id28" name="id28">5.2.4 Invoke <tt class="docutils literal"><span class="pre">bjam</span></tt></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#expected-build-output" id="id29" name="id29">5.3 Expected Build Output</a></li>
|
||||
<li><a class="reference" href="#in-case-of-build-errors" id="id30" name="id30">5.4 In Case of Build Errors</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#link-your-program-to-a-boost-library" id="id31" name="id31">6 Link Your Program to a Boost Library</a><ul class="auto-toc">
|
||||
<li><a class="reference" href="#library-naming" id="id32" name="id32">6.1 Library Naming</a></li>
|
||||
<li><a class="reference" href="#test-your-program" id="id33" name="id33">6.2 Test Your Program</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#conclusion-and-further-resources" id="id34" name="id34">7 Conclusion and Further Resources</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id17" id="get-boost" name="get-boost">1 Get Boost</a></h1>
|
||||
<p>The most reliable way to get a copy of Boost is to download a
|
||||
distribution from <a class="reference" href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041&release_id=376197">SourceForge</a>:</p>
|
||||
<ol class="arabic">
|
||||
<li><p class="first">Download <tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt><tt class="docutils literal"><span class="pre">.tar.bz2</span></tt>.</p>
|
||||
</li>
|
||||
<li><p class="first">In the directory where you want to put the Boost installation,
|
||||
execute</p>
|
||||
<pre class="literal-block">
|
||||
tar --bzip2 -xf <em>/path/to/</em><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>.tar.bz2
|
||||
</pre>
|
||||
</li>
|
||||
</ol>
|
||||
<div class="admonition-other-packages admonition">
|
||||
<p class="first admonition-title">Other Packages</p>
|
||||
<p class="last">RedHat, Debian, and other distribution packagers supply Boost
|
||||
library packages, however you may need to adapt these
|
||||
instructions if you use third-party packages, because their
|
||||
creators usually choose to break Boost up into several packages,
|
||||
reorganize the directory structure of the Boost distribution,
|
||||
and/or rename the library binaries.<a class="footnote-reference" href="#packagers" id="id2" name="id2"><sup>1</sup></a> If you have
|
||||
any trouble, we suggest using an official Boost distribution
|
||||
from <a class="reference" href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041&release_id=376197">SourceForge</a>.</p>
|
||||
</div>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id18" id="the-boost-distribution" name="the-boost-distribution">2 The Boost Distribution</a></h1>
|
||||
<p>This is is a sketch of the directory structure you'll end up with:</p>
|
||||
<pre class="literal-block">
|
||||
<strong>boost_1_34_0</strong><strong>/</strong> .................<em>The “boost root directory”</em>
|
||||
<strong>index.htm</strong> .........<em>A copy of www.boost.org starts here</em>
|
||||
<strong>boost</strong><strong>/</strong> .........................<em>All Boost Header files</em>
|
||||
<tt class="docutils literal"> </tt>
|
||||
<strong>libs</strong><strong>/</strong> ............<em>Tests, .cpp</em>s<em>, docs, etc., by library</em>
|
||||
<strong>index.html</strong> ........<em>Library documentation starts here</em>
|
||||
<strong>algorithm</strong><strong>/</strong>
|
||||
<strong>any</strong><strong>/</strong>
|
||||
<strong>array</strong><strong>/</strong>
|
||||
<em>…more libraries…</em>
|
||||
<strong>status</strong><strong>/</strong> .........................<em>Boost-wide test suite</em>
|
||||
<strong>tools</strong><strong>/</strong> ...........<em>Utilities, e.g. bjam, quickbook, bcp</em>
|
||||
<strong>more</strong><strong>/</strong> ..........................<em>Policy documents, etc.</em>
|
||||
<strong>doc</strong><strong>/</strong> ...............<em>A subset of all Boost library docs</em>
|
||||
</pre>
|
||||
<div class="sidebar">
|
||||
<p class="first sidebar-title">Header Organization</p>
|
||||
<p class="pre-wrap">The organization of Boost library headers isn't entirely uniform,
|
||||
but most libraries follow a few patterns:</p>
|
||||
<ul class="pre-wrap last">
|
||||
<li><p class="first">Some older libraries and most very small libraries place all
|
||||
public headers directly into <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt>.</p>
|
||||
</li>
|
||||
<li><p class="first">Most libraries' public headers live in a subdirectory of
|
||||
<tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt>, named after the library. For example, you'll find
|
||||
the Python library's <tt class="docutils literal"><span class="pre">def.hpp</span></tt> header in</p>
|
||||
<pre class="literal-block">
|
||||
<tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt><tt class="docutils literal"><span class="pre">python</span></tt><tt class="docutils literal"><span class="pre">/</span></tt><tt class="docutils literal"><span class="pre">def.hpp</span></tt>.
|
||||
</pre>
|
||||
</li>
|
||||
<li><p class="first">Some libraries have an “aggregate header” in <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt> that
|
||||
<tt class="docutils literal"><span class="pre">#include</span></tt>s all of the library's other headers. For
|
||||
example, <a class="reference" href="../../libs/python/doc/building.html">Boost.Python</a>'s aggregate header is</p>
|
||||
<pre class="literal-block">
|
||||
<tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt><tt class="docutils literal"><span class="pre">python.hpp</span></tt>.
|
||||
</pre>
|
||||
</li>
|
||||
<li><p class="first">Most libraries place private headers in a subdirectory called
|
||||
<tt class="docutils literal"><span class="pre">detail</span></tt><tt class="docutils literal"><span class="pre">/</span></tt>, or <tt class="docutils literal"><span class="pre">aux_</span></tt><tt class="docutils literal"><span class="pre">/</span></tt>. Don't expect to find
|
||||
anything you can use in these directories.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<p>It's important to note the following:</p>
|
||||
<ol class="arabic" id="boost-root-directory">
|
||||
<li><p class="first">The path to the <strong>boost root directory</strong> (often <tt class="docutils literal"><span class="pre">/usr/local/</span></tt><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>) is
|
||||
sometimes referred to as <tt class="docutils literal"><span class="pre">$BOOST_ROOT</span></tt> in documentation and
|
||||
mailing lists .</p>
|
||||
</li>
|
||||
<li><p class="first">To compile anything in Boost, you need a directory containing
|
||||
the <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt> subdirectory in your <tt class="docutils literal"><span class="pre">#include</span></tt> path. <tt class="docutils literal"> </tt></p>
|
||||
</li>
|
||||
<li><p class="first">Since all of Boost's header files have the <tt class="docutils literal"><span class="pre">.hpp</span></tt> extension,
|
||||
and live in the <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt> subdirectory of the boost root, your
|
||||
Boost <tt class="docutils literal"><span class="pre">#include</span></tt> directives will look like:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/<em>whatever</em>.hpp>
|
||||
</pre>
|
||||
<p>or</p>
|
||||
<pre class="literal-block">
|
||||
#include "boost/<em>whatever</em>.hpp"
|
||||
</pre>
|
||||
<p>depending on your religion as regards the use of angle bracket
|
||||
includes. <tt class="docutils literal"> </tt></p>
|
||||
</li>
|
||||
<li><p class="first">Don't be distracted by the <tt class="docutils literal"><span class="pre">doc</span></tt><tt class="docutils literal"><span class="pre">/</span></tt> subdirectory; it only
|
||||
contains a subset of the Boost documentation. Start with
|
||||
<tt class="docutils literal"><span class="pre">libs</span></tt><tt class="docutils literal"><span class="pre">/</span></tt><tt class="docutils literal"><span class="pre">index.html</span></tt> if you're looking for the whole enchilada.</p>
|
||||
</li>
|
||||
</ol>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id19" id="header-only-libraries" name="header-only-libraries">3 Header-Only Libraries</a></h1>
|
||||
<p>The first thing many people want to know is, “how do I build
|
||||
Boost?” The good news is that often, there's nothing to build.</p>
|
||||
<div class="admonition-nothing-to-build admonition">
|
||||
<p class="first admonition-title">Nothing to Build?</p>
|
||||
<p class="last">Most Boost libraries are <strong>header-only</strong>: they consist <em>entirely
|
||||
of header files</em> containing templates and inline functions, and
|
||||
require no separately-compiled library binaries or special
|
||||
treatment when linking.</p>
|
||||
</div>
|
||||
<p id="separate">The only Boost libraries that <em>must</em> be built separately are:</p>
|
||||
<ul class="simple">
|
||||
<li><a class="reference" href="../../libs/filesystem/index.html">Boost.Filesystem</a></li>
|
||||
<li><a class="reference" href="../../libs/iostreams/index.html">Boost.IOStreams</a></li>
|
||||
<li><a class="reference" href="../../libs/program_options/index.html">Boost.ProgramOptions</a></li>
|
||||
<li><a class="reference" href="../../libs/python/doc/building.html">Boost.Python</a></li>
|
||||
<li><a class="reference" href="../../libs/regex/index.html">Boost.Regex</a></li>
|
||||
<li><a class="reference" href="../../libs/serialization/index.html">Boost.Serialization</a></li>
|
||||
<li><a class="reference" href="../../libs/signals/index.html">Boost.Signals</a></li>
|
||||
<li><a class="reference" href="../../libs/thread/index.html">Boost.Thread</a></li>
|
||||
<li><a class="reference" href="../../libs/wave/index.html">Boost.Wave</a></li>
|
||||
</ul>
|
||||
<p>A few libraries have optional separately-compiled binaries:</p>
|
||||
<ul class="simple">
|
||||
<li><a class="reference" href="../../libs/date_time/index.html">Boost.DateTime</a> has a binary component that is only needed if
|
||||
you're using its <tt class="docutils literal"><span class="pre">to_string</span></tt>/<tt class="docutils literal"><span class="pre">from_string</span></tt> or serialization
|
||||
features, or if you're targeting Visual C++ 6.x or Borland.</li>
|
||||
<li><a class="reference" href="../../libs/graph/index.html">Boost.Graph</a> also has a binary component that is only needed if
|
||||
you intend to <a class="reference" href="../../libs/graph/doc/read_graphviz.html">parse GraphViz files</a>.</li>
|
||||
<li><a class="reference" href="../../libs/test/index.html">Boost.Test</a> can be used in “header-only” or “separately compiled”
|
||||
mode, although <strong>separate compilation is recommended for serious
|
||||
use</strong>.</li>
|
||||
</ul>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id20" id="build-a-simple-program-using-boost" name="build-a-simple-program-using-boost">4 Build a Simple Program Using Boost</a></h1>
|
||||
<p>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:</p>
|
||||
<pre class="literal-block">
|
||||
#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) << " " );
|
||||
}
|
||||
</pre>
|
||||
<p>Copy the text of this program into a file called <tt class="docutils literal"><span class="pre">example.cpp</span></tt>.</p>
|
||||
<p>Now, in the directory where you saved <tt class="docutils literal"><span class="pre">example.cpp</span></tt>, issue the
|
||||
following command:</p>
|
||||
<pre class="literal-block">
|
||||
c++ -I <em>path/to/</em><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt> example.cpp -o example
|
||||
</pre>
|
||||
<p>To test the result, type:</p>
|
||||
<pre class="literal-block">
|
||||
echo 1 2 3 | ./example
|
||||
</pre>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id21" id="errors-and-warnings" name="errors-and-warnings">4.1 Errors and Warnings</a></h2>
|
||||
<p>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.<a class="footnote-reference" href="#warnings" id="id4" name="id4"><sup>3</sup></a> <strong>Errors are another matter</strong>. If you're
|
||||
seeing compilation errors at this point in the tutorial, check to
|
||||
be sure you've copied the <a class="reference" href="#build-a-simple-program-using-boost">example program</a> correctly and that you've
|
||||
correctly identified the <a class="reference" href="#boost-root-directory">Boost root directory</a>.</p>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id22" id="prepare-to-use-a-boost-library-binary" name="prepare-to-use-a-boost-library-binary">5 Prepare to Use a Boost Library Binary</a></h1>
|
||||
<p>If you want to use any of the separately-compiled Boost libraries,
|
||||
you'll need to acquire library binaries.</p>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id23" id="easy-build-and-install" name="easy-build-and-install">5.1 Easy Build and Install</a></h2>
|
||||
<p>Issue the following commands in the shell (don't type <tt class="docutils literal"><span class="pre">$</span></tt>; that
|
||||
represents the shell's prompt):</p>
|
||||
<pre class="literal-block">
|
||||
<strong>$</strong> cd <em>path/to/</em><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>
|
||||
<strong>$</strong> ./configure --help
|
||||
</pre>
|
||||
<p>Select your configuration options and invoke <tt class="docutils literal"><span class="pre">./configure</span></tt> again
|
||||
without the <tt class="docutils literal"><span class="pre">--help</span></tt> option. Unless you have write permission in
|
||||
your system's <tt class="docutils literal"><span class="pre">/usr/local/</span></tt> directory, you'll probably want to at
|
||||
least use</p>
|
||||
<pre class="literal-block">
|
||||
<strong>$</strong> ./configure <strong>--prefix=</strong><em>path</em>/<em>to</em>/<em>installation</em>/<em>prefix</em>
|
||||
</pre>
|
||||
<p>to install somewhere else. Also, consider using the
|
||||
<tt class="docutils literal"><span class="pre">--show-libraries</span></tt> and <tt class="docutils literal"><span class="pre">--with-libraries=</span></tt> options to limit the
|
||||
long wait you'll experience if you build everything. Finally,</p>
|
||||
<pre class="literal-block">
|
||||
<strong>$</strong> make install
|
||||
</pre>
|
||||
<p>will leave Boost binaries in the <tt class="docutils literal"><span class="pre">lib/</span></tt> subdirectory of your
|
||||
installation prefix. You will also find a copy of the Boost
|
||||
headers in the <tt class="docutils literal"><span class="pre">include/</span></tt> subdirectory of the installation
|
||||
prefix, so you can henceforth use that directory as an <tt class="docutils literal"><span class="pre">#include</span></tt>
|
||||
path in place of the Boost root directory.</p>
|
||||
<p><a class="reference" href="#link-your-program-to-a-boost-library"><em>skip to the next step</em></a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id24" id="or-custom-build-and-install" name="or-custom-build-and-install">5.2 Or, Custom Build and Install</a></h2>
|
||||
<p>If you're using a compiler other than your system's default, you'll
|
||||
need to use <a class="reference" href="../../tools/build/index.html">Boost.Build</a> to create binaries. You'll also
|
||||
use this method if you need a nonstandard build variant (see the
|
||||
<a class="reference" href="../../tools/build/index.html">Boost.Build documentation</a> for more details).</p>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<p><a class="reference" href="../../tools/build/index.html">Boost.Build</a> is a text-based system for developing, testing, and
|
||||
installing software. To use it, you'll need an executable called
|
||||
<tt class="docutils literal"><span class="pre">bjam</span></tt>.</p>
|
||||
<div class="section">
|
||||
<h3><a class="toc-backref" href="#id25" id="get-bjam" name="get-bjam">5.2.1 Get <tt class="docutils literal"><span class="pre">bjam</span></tt></a></h3>
|
||||
<p><tt class="docutils literal"><span class="pre">bjam</span></tt> is the command-line tool that drives the Boost Build
|
||||
system. To build Boost binaries, you'll invoke <tt class="docutils literal"><span class="pre">bjam</span></tt> from the
|
||||
Boost root.</p>
|
||||
<p>Boost provides <a class="reference" href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=72941">pre-compiled <tt class="docutils literal"><span class="pre">bjam</span></tt> executables</a> for a variety of platforms.
|
||||
Alternatively, you can build <tt class="docutils literal"><span class="pre">bjam</span></tt> yourself using <a class="reference" href="../../doc/html/jam/building.html">these
|
||||
instructions</a>.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h3><a class="toc-backref" href="#id26" id="identify-your-toolset" name="identify-your-toolset"><span id="toolset-name"></span><span id="toolset"></span>5.2.2 Identify Your Toolset</a></h3>
|
||||
<p>First, find the toolset corresponding to your compiler in the
|
||||
following table.</p>
|
||||
<table border="1" class="docutils table">
|
||||
<colgroup>
|
||||
<col width="18%" />
|
||||
<col width="33%" />
|
||||
<col width="48%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th class="head">Toolset
|
||||
Name</th>
|
||||
<th class="head">Vendor</th>
|
||||
<th class="head">Notes</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><tt class="docutils literal"><span class="pre">acc</span></tt></td>
|
||||
<td>Hewlett Packard</td>
|
||||
<td>Only very recent versions are
|
||||
known to work well with Boost</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">borland</span></tt></td>
|
||||
<td>Borland</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">como</span></tt></td>
|
||||
<td>Comeau Computing</td>
|
||||
<td>Using this toolset may
|
||||
require <a class="reference" href="../../tools/build/index.html">configuring</a> another
|
||||
toolset to act as its backend</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">cw</span></tt></td>
|
||||
<td>Metrowerks/FreeScale</td>
|
||||
<td>The CodeWarrior compiler. We
|
||||
have not tested versions of
|
||||
this compiler produced since
|
||||
it was sold to FreeScale.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">dmc</span></tt></td>
|
||||
<td>Digital Mars</td>
|
||||
<td>As of this Boost release, no
|
||||
version of dmc is known to
|
||||
handle Boost well.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">darwin</span></tt></td>
|
||||
<td>Apple Computer</td>
|
||||
<td>Apple's version of the GCC
|
||||
toolchain with support for
|
||||
Darwin and MacOS X features
|
||||
such as frameworks.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">gcc</span></tt></td>
|
||||
<td>The Gnu Project</td>
|
||||
<td>Includes support for Cygwin
|
||||
and MinGW compilers.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">hp_cxx</span></tt></td>
|
||||
<td>Hewlett Packard</td>
|
||||
<td>Targeted at the Tru64
|
||||
operating system.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">intel</span></tt></td>
|
||||
<td>Intel</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">kylix</span></tt></td>
|
||||
<td>Borland</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">msvc</span></tt></td>
|
||||
<td>Microsoft</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">qcc</span></tt></td>
|
||||
<td>QNX Software Systems</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">sun</span></tt></td>
|
||||
<td>Sun</td>
|
||||
<td>Only very recent versions are
|
||||
known to work well with
|
||||
Boost.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">vacpp</span></tt></td>
|
||||
<td>IBM</td>
|
||||
<td>The VisualAge C++ compiler.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>If you have multiple versions of a particular compiler installed,
|
||||
you can append the version number to the toolset name, preceded by a
|
||||
hyphen, e.g. <tt class="docutils literal"><span class="pre">msvc-7.1</span></tt> or <tt class="docutils literal"><span class="pre">gcc-3.4</span></tt>.</p>
|
||||
<div class="note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">if you built <tt class="docutils literal"><span class="pre">bjam</span></tt> yourself, you may
|
||||
have selected a toolset name for that purpose, but that does not
|
||||
affect this step in any way; you still need to select a Boost.Build
|
||||
toolset from the table.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h3><a class="toc-backref" href="#id27" id="select-a-build-directory" name="select-a-build-directory"><span id="id9"></span><span id="build-directory"></span>5.2.3 Select a Build Directory</a></h3>
|
||||
<p><a class="reference" href="../../tools/build/index.html">Boost.Build</a> will place all intermediate files it generates while
|
||||
building into the <strong>build directory</strong>. If your Boost root
|
||||
directory is writable, this step isn't strictly necessary: by
|
||||
default Boost.Build will create a <tt class="docutils literal"><span class="pre">bin.v2/</span></tt> subdirectory for that
|
||||
purpose in your current working directory.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h3><a class="toc-backref" href="#id28" id="invoke-bjam" name="invoke-bjam">5.2.4 Invoke <tt class="docutils literal"><span class="pre">bjam</span></tt></a></h3>
|
||||
<p>Change your current directory to the Boost root directory and
|
||||
invoke <tt class="docutils literal"><span class="pre">bjam</span></tt> as follows:</p>
|
||||
<pre class="literal-block">
|
||||
bjam <strong>--build-dir=</strong><a class="reference" href="#id9"><em>build-directory</em></a> <strong>--toolset=</strong><a class="reference" href="#toolset-name"><em>toolset-name</em></a> stage
|
||||
</pre>
|
||||
<p>For example, your session might look like this:</p>
|
||||
<pre class="literal-block">
|
||||
$ cd ~/<tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>
|
||||
$ bjam <strong>--build-dir=</strong>/tmp/build-boost <strong>--toolset=</strong>gcc
|
||||
</pre>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<p>Boost.Build will place the Boost binaries in the <tt class="docutils literal"><span class="pre">stage</span></tt><tt class="docutils literal"><span class="pre">/</span></tt>
|
||||
subdirectory of your <a class="reference" href="#build-directory">build directory</a>.</p>
|
||||
<div class="note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last"><tt class="docutils literal"><span class="pre">bjam</span></tt> is case-sensitive; it is important that all the
|
||||
parts shown in <strong>bold</strong> type above be entirely lower-case.</p>
|
||||
</div>
|
||||
<p>For a description of other options you can pass when invoking
|
||||
<tt class="docutils literal"><span class="pre">bjam</span></tt>, type:</p>
|
||||
<pre class="literal-block">
|
||||
bjam --help
|
||||
</pre>
|
||||
<p>In particular, to limit the amount of time spent building, you may
|
||||
be interested in:</p>
|
||||
<ul class="simple">
|
||||
<li>reviewing the list of library names with <tt class="docutils literal"><span class="pre">--show-libraries</span></tt></li>
|
||||
<li>limiting which libraries get built with the <tt class="docutils literal"><span class="pre">--with-</span></tt><em>library-name</em> or <tt class="docutils literal"><span class="pre">--without-</span></tt><em>library-name</em> options</li>
|
||||
<li>choosing a specific build variant by adding <tt class="docutils literal"><span class="pre">release</span></tt> or
|
||||
<tt class="docutils literal"><span class="pre">debug</span></tt> to the command line.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id29" id="expected-build-output" name="expected-build-output">5.3 Expected Build Output</a></h2>
|
||||
<p>During the process of building Boost libraries, you can expect to
|
||||
see some messages printed on the console. These may include</p>
|
||||
<ul>
|
||||
<li><p class="first">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.</p>
|
||||
</li>
|
||||
<li><p class="first">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.</p>
|
||||
</li>
|
||||
<li><p class="first">Build action messages describing what the tool is doing, which
|
||||
look something like:</p>
|
||||
<pre class="literal-block">
|
||||
<em>toolset-name</em>.c++ <em>long</em>/<em>path</em>/<em>to</em>/<em>file</em>/<em>being</em>/<em>built</em>
|
||||
</pre>
|
||||
</li>
|
||||
<li><p class="first">Compiler warnings.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id30" id="in-case-of-build-errors" name="in-case-of-build-errors">5.4 In Case of Build Errors</a></h2>
|
||||
<p>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 <a class="reference" href="../../libs/iostreams/doc/installation.html">here</a>. Install the relevant development
|
||||
packages for libz and libbz2 if you need those features. Other
|
||||
errors when building Boost libraries are cause for concern.</p>
|
||||
<p>If it seems like the build system can't find your compiler and/or
|
||||
linker, consider setting up a <tt class="docutils literal"><span class="pre">user-config.jam</span></tt> file as described
|
||||
in the <a class="reference" href="../../tools/build/index.html">Boost.Build documentation</a>. If that isn't your problem or
|
||||
the <tt class="docutils literal"><span class="pre">user-config.jam</span></tt> file doesn't work for you, please address
|
||||
questions about configuring Boost for your compiler to the
|
||||
<a class="reference" href="../../more/mailing_lists.htm#jamboost">Boost.Build mailing list</a>.</p>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id31" id="link-your-program-to-a-boost-library" name="link-your-program-to-a-boost-library">6 Link Your Program to a Boost Library</a></h1>
|
||||
<p>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 <a class="reference" href="../../libs/regex/index.html">Boost.Regex</a> library, which has a
|
||||
separately-compiled binary component.</p>
|
||||
<pre class="literal-block">
|
||||
#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;
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
<p>There are two main challenges associated with linking:</p>
|
||||
<ol class="arabic simple">
|
||||
<li>Tool configuration, e.g. choosing command-line options or IDE
|
||||
build settings.</li>
|
||||
<li>Identifying the library binary, among all the build variants,
|
||||
whose compile configuration is compatible with the rest of your
|
||||
project.</li>
|
||||
</ol>
|
||||
<p>There are two main ways to link to libraries:</p>
|
||||
<ol class="upperalpha">
|
||||
<li><p class="first">You can specify the full path to each library:</p>
|
||||
<pre class="literal-block">
|
||||
$ c++ -I <em>path/to/</em><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt> example.cpp -o example <strong>\</strong>
|
||||
<strong>~/boost/lib/libboost_regex-gcc-3.4-mt-d-1_34.a</strong>
|
||||
</pre>
|
||||
</li>
|
||||
<li><p class="first">You can separately specify a directory to search (with <tt class="docutils literal"><span class="pre">-L</span></tt><em>directory</em>) and a library name to search for (with <tt class="docutils literal"><span class="pre">-l</span></tt><em>library</em>,<a class="footnote-reference" href="#lowercase-l" id="id11" name="id11"><sup>2</sup></a> dropping the filename's leading <tt class="docutils literal"><span class="pre">lib</span></tt> and trailing
|
||||
suffix (<tt class="docutils literal"><span class="pre">.a</span></tt> in this case):</p>
|
||||
<pre class="literal-block">
|
||||
$ c++ -I <em>path/to/</em><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt> example.cpp -o example <strong>\</strong>
|
||||
<strong>-L~/boost/lib/ -lboost_regex-gcc-3.4-mt-d-1_34</strong>
|
||||
</pre>
|
||||
<p>As you can see, this method is just as terse as method A for one
|
||||
library; it <em>really</em> pays off when you're using multiple
|
||||
libraries from the same directory. Note, however, that if you
|
||||
use this method with a library that has both static (<tt class="docutils literal"><span class="pre">.a</span></tt>) and
|
||||
dynamic (<tt class="docutils literal"><span class="pre">.so</span></tt>) builds, the system may choose one
|
||||
automatically for you unless you pass a special option such as
|
||||
<tt class="docutils literal"><span class="pre">-static</span></tt> on the command line.</p>
|
||||
</li>
|
||||
</ol>
|
||||
<p>In both cases above, the bold text is what you'd add to <a class="reference" href="#build-a-simple-program-using-boost">the
|
||||
command lines we explored earlier</a>.</p>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id32" id="library-naming" name="library-naming">6.1 Library Naming</a></h2>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<p>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,
|
||||
<tt class="docutils literal"><span class="pre">libboost_regex-vc71-mt-d-1_34.lib</span></tt> can be broken down into the
|
||||
following elements:</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">lib</span></tt></dt>
|
||||
<dd><em>Prefix</em>: except on Microsoft Windows, every Boost library
|
||||
name begins with this string. On Windows, only ordinary static
|
||||
libraries use the <tt class="docutils literal"><span class="pre">lib</span></tt> prefix; import libraries and DLLs do
|
||||
not.<a class="footnote-reference" href="#distinct" id="id13" name="id13"><sup>4</sup></a></dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">boost_regex</span></tt></dt>
|
||||
<dd><em>Library name</em>: all boost library filenames begin with <tt class="docutils literal"><span class="pre">boost_</span></tt>.</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">-vc71</span></tt></dt>
|
||||
<dd><em>Toolset tag</em>: identifies the toolset and version used to build
|
||||
the binary.</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">-mt</span></tt></dt>
|
||||
<dd><em>Threading tag</em>: indicates that the library was
|
||||
built with multithreading support enabled. Libraries built
|
||||
without multithreading support can be identified by the absence
|
||||
of <tt class="docutils literal"><span class="pre">-mt</span></tt>.</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">-d</span></tt></dt>
|
||||
<dd><p class="first"><em>ABI tag</em>: encodes details that affect the library's
|
||||
interoperability with other compiled code. For each such
|
||||
feature, a single letter is added to the tag:</p>
|
||||
<blockquote>
|
||||
<table border="1" class="docutils table">
|
||||
<colgroup>
|
||||
<col width="6%" />
|
||||
<col width="94%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th class="head">Key</th>
|
||||
<th class="head">Use this library when:</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><tt class="docutils literal"><span class="pre">s</span></tt></td>
|
||||
<td>linking statically to the C++ standard library and compiler runtime support
|
||||
libraries.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">g</span></tt></td>
|
||||
<td>using debug versions of the standard and runtime support libraries.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">y</span></tt></td>
|
||||
<td>using a special <a class="reference" href="../../libs/python/doc/building.html#variants">debug build of Python</a>.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">d</span></tt></td>
|
||||
<td>building a debug version of your code.<a class="footnote-reference" href="#debug-abi" id="id14" name="id14"><sup>5</sup></a></td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">p</span></tt></td>
|
||||
<td>using the STLPort standard library rather than the default one supplied with
|
||||
your compiler.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">n</span></tt></td>
|
||||
<td>using STLPort's deprecated “native iostreams” feature.<a class="footnote-reference" href="#native" id="id15" name="id15"><sup>6</sup></a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</blockquote>
|
||||
<p class="last">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 in “native iostreams” mode,
|
||||
the tag would be: <tt class="docutils literal"><span class="pre">-sgdpn</span></tt>. If none of the above apply, the
|
||||
ABI tag is ommitted.</p>
|
||||
</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">-1_34</span></tt></dt>
|
||||
<dd><em>Version tag</em>: the full Boost release number, with periods
|
||||
replaced by underscores. For example, version 1.31.1 would be
|
||||
tagged as "-1_31_1".</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">.lib</span></tt></dt>
|
||||
<dd><em>Extension</em>: determined according to the operating system's usual
|
||||
convention. On most *nix platforms the extensions are <tt class="docutils literal"><span class="pre">.a</span></tt>
|
||||
and <tt class="docutils literal"><span class="pre">.so</span></tt> for static libraries (archives) and shared libraries,
|
||||
respectively. On Windows, <tt class="docutils literal"><span class="pre">.dll</span></tt> indicates a shared library
|
||||
and—except for static libraries built by <tt class="docutils literal"><span class="pre">gcc</span></tt> toolset, whose
|
||||
names always end in <tt class="docutils literal"><span class="pre">.a``—</span> <span class="pre">``.lib</span></tt> indicates a static or import
|
||||
library. Where supported by *nix toolsets, 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.</dd>
|
||||
</dl>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id33" id="test-your-program" name="test-your-program">6.2 Test Your Program</a></h2>
|
||||
<p>To test our subject extraction, we'll filter the following text
|
||||
file. Copy it out of your browser and save it as <tt class="docutils literal"><span class="pre">jayne.txt</span></tt>:</p>
|
||||
<pre class="literal-block">
|
||||
To: George Shmidlap
|
||||
From: Rita Marlowe
|
||||
Subject: Will Success Spoil Rock Hunter?
|
||||
---
|
||||
See subject.
|
||||
</pre>
|
||||
<p>If you linked to a shared library, you may need to prepare some
|
||||
platform-specific settings so that the system will be able to find
|
||||
and load it when your program is run. Most platforms have an
|
||||
environment variable to which you can add the directory containing
|
||||
the library. On many platforms (Linux, FreeBSD) that variable is
|
||||
<tt class="docutils literal"><span class="pre">LD_LIBRARY_PATH</span></tt>, but on MacOS it's <tt class="docutils literal"><span class="pre">DYLD_LIBRARY_PATH</span></tt>, and
|
||||
on Cygwin it's simply <tt class="docutils literal"><span class="pre">PATH</span></tt>. In most shells other than <tt class="docutils literal"><span class="pre">csh</span></tt>
|
||||
and <tt class="docutils literal"><span class="pre">tcsh</span></tt>, you can adjust the variable as follows (again, don't
|
||||
type the <tt class="docutils literal"><span class="pre">$</span></tt>—that represents the shell prompt):</p>
|
||||
<pre class="literal-block">
|
||||
<strong>$</strong> <em>VARIABLE_NAME</em>=<em>path/to/lib/directory</em>:${<em>VARIABLE_NAME</em>}
|
||||
<strong>$</strong> export <em>VARIABLE_NAME</em>
|
||||
</pre>
|
||||
<p>On <tt class="docutils literal"><span class="pre">csh</span></tt> and <tt class="docutils literal"><span class="pre">tcsh</span></tt>, it's</p>
|
||||
<pre class="literal-block">
|
||||
<strong>$</strong> setenv <em>VARIABLE_NAME</em> <em>path/to/lib/directory</em>:${<em>VARIABLE_NAME</em>}
|
||||
</pre>
|
||||
<p>Once the necessary variable (if any) is set, you can run your
|
||||
program as follows:</p>
|
||||
<pre class="literal-block">
|
||||
<strong>$</strong> <em>path</em>/<em>to</em>/<em>compiled</em>/example < <em>path</em>/<em>to</em>/jayne.txt
|
||||
</pre>
|
||||
<p>The program should respond with the email subject, “Will Success
|
||||
Spoil Rock Hunter?”</p>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id34" id="conclusion-and-further-resources" name="conclusion-and-further-resources">7 Conclusion and Further Resources</a></h1>
|
||||
<p>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 <a class="reference" href="../../more/mailing_lists.htm#users">Boost Users'
|
||||
mailing list</a>.</p>
|
||||
<ul class="simple">
|
||||
<li><a class="reference" href="../tools/build/v2">Boost.Build reference manual</a></li>
|
||||
<li><a class="reference" href="../../tools/jam/index.html">Boost.Jam reference manual</a></li>
|
||||
<li><a class="reference" href="../../more/mailing_lists.htm#users">Boost Users' mailing list</a></li>
|
||||
<li><a class="reference" href="../../more/mailing_lists.htm#jamboost">Boost.Build mailing list</a></li>
|
||||
<li><a class="reference" href="http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Boost.Build_V2">Boost.Build Wiki</a></li>
|
||||
<li><a class="reference" href="../../libs/index.html">Index of all Boost library documentation</a></li>
|
||||
</ul>
|
||||
<div class="admonition-onward admonition">
|
||||
<p class="first admonition-title">Onward</p>
|
||||
<blockquote class="epigraph last">
|
||||
<p>Good luck, and have fun!</p>
|
||||
<p class="attribution">—the Boost Developers</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
<hr class="docutils" />
|
||||
<table class="docutils footnote" frame="void" id="packagers" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id2" name="packagers">[1]</a></td><td><p class="first">If developers of Boost packages would like to work
|
||||
with us to make sure these instructions can be used with their
|
||||
packages, we'd be glad to help. Please make your interest known
|
||||
to the <a class="reference" href="../../more/mailing_lists.htm#main">Boost developers' list</a>.</p>
|
||||
</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="lowercase-l" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id11" name="lowercase-l">[2]</a></td><td>That option is a dash followed by a lowercase “L”
|
||||
character, which looks very much like a numeral 1 in some fonts.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<table class="docutils footnote" frame="void" id="warnings" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id4" name="warnings">[3]</a></td><td>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.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="distinct" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id13" name="distinct">[4]</a></td><td>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.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="debug-abi" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id14" name="debug-abi">[5]</a></td><td>These libraries were compiled without optimization
|
||||
or inlining, with full debug symbols enabled, and without
|
||||
<tt class="docutils literal"><span class="pre">NDEBUG</span></tt> <tt class="docutils literal"><span class="pre">#define</span></tt>d. All though 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.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="native" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id15" name="native">[6]</a></td><td>This feature of STLPort is deprecated because it's
|
||||
impossible to make it work transparently to the user; we don't
|
||||
recommend it.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<!-- This file contains all the definitions that need to be updated -->
|
||||
<!-- for each new release of Boost. -->
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
236
getting_started/unix-variants.rst
Normal file
236
getting_started/unix-variants.rst
Normal file
@ -0,0 +1,236 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
=============================================
|
||||
|(logo)|__ Getting Started on Unix Variants
|
||||
=============================================
|
||||
|
||||
.. meta::
|
||||
:description: Getting Started with Boost on Unix Variants (including Linux and MacOS)
|
||||
|
||||
.. |(logo)| image:: ../../boost.png
|
||||
:alt: Boost
|
||||
:class: boost-logo
|
||||
|
||||
__ ../../index.htm
|
||||
|
||||
.. section-numbering::
|
||||
|
||||
.. maybe we don't need this
|
||||
.. Admonition:: A note to Cygwin_ and MinGW_ users
|
||||
|
||||
If you plan to build from the Cygwin_ bash shell, you're in the
|
||||
right place. If you plan to use your tools from the Windows
|
||||
command prompt, you should follow the instructions for `getting
|
||||
started on Windows`_. Other command shells, such as MinGW_\ 's
|
||||
MSYS, are not supported—they may or may not work.
|
||||
|
||||
.. _`Getting Started on Windows`: windows.html
|
||||
.. _Cygwin: http://www.cygwin.com
|
||||
.. _MinGW: http://mingw.org
|
||||
|
||||
.. Contents:: Index
|
||||
|
||||
Get Boost
|
||||
=========
|
||||
|
||||
The most reliable way to get a copy of Boost is to download a
|
||||
distribution from SourceForge_:
|
||||
|
||||
.. _SourceForge: `sf-download`_
|
||||
|
||||
1. Download |boost.tar.bz2|.
|
||||
|
||||
2. In the directory where you want to put the Boost installation,
|
||||
execute
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
tar --bzip2 -xf */path/to/*\ |boost_ver|\ .tar.bz2
|
||||
|
||||
.. |boost.tar.bz2| replace:: |boost_ver|\ ``.tar.bz2``
|
||||
|
||||
.. _`boost.tar.bz2`: `sf-download`_
|
||||
|
||||
.. Admonition:: Other Packages
|
||||
|
||||
RedHat, Debian, and other distribution packagers supply Boost
|
||||
library packages, however you may need to adapt these
|
||||
instructions if you use third-party packages, because their
|
||||
creators usually choose to break Boost up into several packages,
|
||||
reorganize the directory structure of the Boost distribution,
|
||||
and/or rename the library binaries. [#packagers]_ If you have
|
||||
any trouble, we suggest using an official Boost distribution
|
||||
from SourceForge_.
|
||||
|
||||
.. include:: detail/distro.rst
|
||||
|
||||
.. include:: detail/header-only.rst
|
||||
|
||||
.. include:: detail/build-simple-head.rst
|
||||
|
||||
Now, in the directory where you saved ``example.cpp``, issue the
|
||||
following command:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
c++ -I |root| example.cpp -o example
|
||||
|
||||
To test the result, type:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
echo 1 2 3 | ./example
|
||||
|
||||
.. include:: detail/errors-and-warnings.rst
|
||||
|
||||
.. include:: detail/binary-head.rst
|
||||
|
||||
Easy Build and Install
|
||||
----------------------
|
||||
|
||||
Issue the following commands in the shell (don't type ``$``; that
|
||||
represents the shell's prompt):
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
**$** cd |root|
|
||||
**$** ./configure --help
|
||||
|
||||
Select your configuration options and invoke ``./configure`` again
|
||||
without the ``--help`` option. Unless you have write permission in
|
||||
your system's ``/usr/local/`` directory, you'll probably want to at
|
||||
least use
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
**$** ./configure **--prefix=**\ *path*\ /\ *to*\ /\ *installation*\ /\ *prefix*
|
||||
|
||||
to install somewhere else. Also, consider using the
|
||||
``--show-libraries`` and ``--with-libraries=`` options to limit the
|
||||
long wait you'll experience if you build everything. Finally,
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
**$** make install
|
||||
|
||||
will leave Boost binaries in the ``lib/`` subdirectory of your
|
||||
installation prefix. You will also find a copy of the Boost
|
||||
headers in the ``include/`` subdirectory of the installation
|
||||
prefix, so you can henceforth use that directory as an ``#include``
|
||||
path in place of the Boost root directory.
|
||||
|
||||
|next|__
|
||||
|
||||
__ `Link Your Program to a Boost Library`_
|
||||
|
||||
Or, Custom Build and Install
|
||||
----------------------------
|
||||
|
||||
If you're using a compiler other than your system's default, you'll
|
||||
need to use Boost.Build_ to create binaries. You'll also
|
||||
use this method if you need a nonstandard build variant (see the
|
||||
`Boost.Build documentation`_ for more details).
|
||||
|
||||
.. include:: detail/build-from-source-head.rst
|
||||
|
||||
For example, your session might look like this:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
$ cd ~/|boost_ver|
|
||||
$ bjam **--build-dir=**\ /tmp/build-boost **--toolset=**\ gcc
|
||||
|
||||
.. include:: detail/build-from-source-tail.rst
|
||||
|
||||
.. include:: detail/link-head.rst
|
||||
|
||||
There are two main ways to link to libraries:
|
||||
|
||||
A. You can specify the full path to each library:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
$ c++ -I |root| example.cpp -o example **\\**
|
||||
**~/boost/lib/libboost_regex-gcc-3.4-mt-d-1_34.a**
|
||||
|
||||
B. You can separately specify a directory to search (with ``-L``\
|
||||
*directory*) and a library name to search for (with ``-l``\
|
||||
*library*, [#lowercase-l]_ dropping the filename's leading ``lib`` and trailing
|
||||
suffix (``.a`` in this case):
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
$ c++ -I |root| example.cpp -o example **\\**
|
||||
**-L~/boost/lib/ -lboost_regex-gcc-3.4-mt-d-1_34**
|
||||
|
||||
As you can see, this method is just as terse as method A for one
|
||||
library; it *really* pays off when you're using multiple
|
||||
libraries from the same directory. Note, however, that if you
|
||||
use this method with a library that has both static (``.a``) and
|
||||
dynamic (``.so``) builds, the system may choose one
|
||||
automatically for you unless you pass a special option such as
|
||||
``-static`` on the command line.
|
||||
|
||||
In both cases above, the bold text is what you'd add to `the
|
||||
command lines we explored earlier`__.
|
||||
|
||||
__ `build a simple program using boost`_
|
||||
|
||||
Library Naming
|
||||
--------------
|
||||
|
||||
.. include:: detail/library-naming.rst
|
||||
|
||||
.. include:: detail/test-head.rst
|
||||
|
||||
If you linked to a shared library, you may need to prepare some
|
||||
platform-specific settings so that the system will be able to find
|
||||
and load it when your program is run. Most platforms have an
|
||||
environment variable to which you can add the directory containing
|
||||
the library. On many platforms (Linux, FreeBSD) that variable is
|
||||
``LD_LIBRARY_PATH``, but on MacOS it's ``DYLD_LIBRARY_PATH``, and
|
||||
on Cygwin it's simply ``PATH``. In most shells other than ``csh``
|
||||
and ``tcsh``, you can adjust the variable as follows (again, don't
|
||||
type the ``$``\ —that represents the shell prompt):
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
**$** *VARIABLE_NAME*\ =\ *path/to/lib/directory*\ :${\ *VARIABLE_NAME*\ }
|
||||
**$** export *VARIABLE_NAME*
|
||||
|
||||
On ``csh`` and ``tcsh``, it's
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
**$** setenv *VARIABLE_NAME* *path/to/lib/directory*\ :${\ *VARIABLE_NAME*\ }
|
||||
|
||||
Once the necessary variable (if any) is set, you can run your
|
||||
program as follows:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
**$** *path*\ /\ *to*\ /\ *compiled*\ /\ example < *path*\ /\ *to*\ /\ jayne.txt
|
||||
|
||||
The program should respond with the email subject, “Will Success
|
||||
Spoil Rock Hunter?”
|
||||
|
||||
.. include:: detail/conclusion.rst
|
||||
|
||||
------------------------------
|
||||
|
||||
.. [#packagers] If developers of Boost packages would like to work
|
||||
with us to make sure these instructions can be used with their
|
||||
packages, we'd be glad to help. Please make your interest known
|
||||
to the `Boost developers' list`_.
|
||||
|
||||
.. _Boost developers' list: ../../more/mailing_lists.htm#main
|
||||
|
||||
.. [#lowercase-l] That option is a dash followed by a lowercase “L”
|
||||
character, which looks very much like a numeral 1 in some fonts.
|
||||
|
||||
.. include:: detail/common-footnotes.rst
|
||||
.. include:: detail/release-variables.rst
|
||||
.. include:: detail/common-unix.rst
|
||||
.. include:: detail/links.rst
|
876
getting_started/windows.html
Normal file
876
getting_started/windows.html
Normal file
@ -0,0 +1,876 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
|
||||
<title>Boost Getting Started on Windows</title>
|
||||
<link rel="stylesheet" href="../../rst.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="logo-getting-started-on-windows">
|
||||
<h1 class="title"><a class="reference" href="../../index.htm"><img alt="Boost" class="boost-logo" src="../../boost.png" /></a> Getting Started on Windows</h1>
|
||||
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<div class="admonition-a-note-to-cygwin-and-mingw-users admonition">
|
||||
<p class="first admonition-title">A note to <a class="reference" href="http://www.cygwin.com">Cygwin</a> and <a class="reference" href="http://mingw.org">MinGW</a> users</p>
|
||||
<p class="last">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 <a class="reference" href="http://www.cygwin.com">Cygwin</a>
|
||||
bash shell, you're actually running on a POSIX platform and
|
||||
should follow the instructions for <a class="reference" href="unix-variants.html">getting started on Unix
|
||||
variants</a>. Other command shells, such as <a class="reference" href="http://mingw.org">MinGW</a>'s MSYS, are
|
||||
not supported—they may or may not work.</p>
|
||||
</div>
|
||||
<div class="contents topic">
|
||||
<p class="topic-title first"><a id="index" name="index">Index</a></p>
|
||||
<ul class="auto-toc simple">
|
||||
<li><a class="reference" href="#get-boost" id="id22" name="id22">1 Get Boost</a></li>
|
||||
<li><a class="reference" href="#the-boost-distribution" id="id23" name="id23">2 The Boost Distribution</a></li>
|
||||
<li><a class="reference" href="#header-only-libraries" id="id24" name="id24">3 Header-Only Libraries</a></li>
|
||||
<li><a class="reference" href="#build-a-simple-program-using-boost" id="id25" name="id25">4 Build a Simple Program Using Boost</a><ul class="auto-toc">
|
||||
<li><a class="reference" href="#build-from-the-visual-studio-ide" id="id26" name="id26">4.1 Build From the Visual Studio IDE</a></li>
|
||||
<li><a class="reference" href="#or-build-from-the-command-prompt" id="id27" name="id27">4.2 Or, Build From the Command Prompt</a></li>
|
||||
<li><a class="reference" href="#errors-and-warnings" id="id28" name="id28">4.3 Errors and Warnings</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#prepare-to-use-a-boost-library-binary" id="id29" name="id29">5 Prepare to Use a Boost Library Binary</a><ul class="auto-toc">
|
||||
<li><a class="reference" href="#install-visual-studio-2005-or-net-2003-binaries" id="id30" name="id30">5.1 Install Visual Studio (2005 or .NET 2003) Binaries</a></li>
|
||||
<li><a class="reference" href="#or-build-and-install-binaries-from-source" id="id31" name="id31">5.2 Or, Build and Install Binaries From Source</a><ul class="auto-toc">
|
||||
<li><a class="reference" href="#get-bjam" id="id32" name="id32">5.2.1 Get <tt class="docutils literal"><span class="pre">bjam</span></tt></a></li>
|
||||
<li><a class="reference" href="#identify-your-toolset" id="id33" name="id33">5.2.2 Identify Your Toolset</a></li>
|
||||
<li><a class="reference" href="#select-a-build-directory" id="id34" name="id34">5.2.3 Select a Build Directory</a></li>
|
||||
<li><a class="reference" href="#invoke-bjam" id="id35" name="id35">5.2.4 Invoke <tt class="docutils literal"><span class="pre">bjam</span></tt></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#expected-build-output" id="id36" name="id36">5.3 Expected Build Output</a></li>
|
||||
<li><a class="reference" href="#in-case-of-build-errors" id="id37" name="id37">5.4 In Case of Build Errors</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#link-your-program-to-a-boost-library" id="id38" name="id38">6 Link Your Program to a Boost Library</a><ul class="auto-toc">
|
||||
<li><a class="reference" href="#link-from-within-the-visual-studio-ide" id="id39" name="id39">6.1 Link From Within the Visual Studio IDE</a></li>
|
||||
<li><a class="reference" href="#or-link-from-the-command-prompt" id="id40" name="id40">6.2 Or, Link From the Command Prompt</a></li>
|
||||
<li><a class="reference" href="#library-naming" id="id41" name="id41">6.3 Library Naming</a></li>
|
||||
<li><a class="reference" href="#test-your-program" id="id42" name="id42">6.4 Test Your Program</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="reference" href="#conclusion-and-further-resources" id="id43" name="id43">7 Conclusion and Further Resources</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id22" id="get-boost" name="get-boost">1 Get Boost</a></h1>
|
||||
<p>The easiest way to get a copy of Boost is to use the <a class="reference" href="http://www.boost-consulting.com/download/windows">installer</a>
|
||||
provided by <a class="reference" href="http://www.boost-consulting.com">Boost Consulting</a>. We especially recommend this
|
||||
method if you use Microsoft Visual Studio .NET 2003 or Microsoft
|
||||
Visual Studio 2005, because the installer can download and install
|
||||
precompiled library binaries, saving you the trouble of building
|
||||
them yourself. To complete this tutorial, you'll need to at least
|
||||
install the <a class="reference" href="../../libs/regex/index.html">Boost.Regex</a> binaries when given the option.</p>
|
||||
<p>If you're using an earlier version of Visual Studio or some other
|
||||
compiler, or if you prefer to build everything yourself, you can
|
||||
download <a class="reference" href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041&release_id=376197"><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt><tt class="docutils literal"><span class="pre">.exe</span></tt></a> and run it to install a complete Boost
|
||||
distribution.<a class="footnote-reference" href="#zip" id="id2" name="id2"><sup>1</sup></a></p>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id23" id="the-boost-distribution" name="the-boost-distribution">2 The Boost Distribution</a></h1>
|
||||
<p>This is is a sketch of the directory structure you'll end up with:</p>
|
||||
<pre class="literal-block">
|
||||
<strong>boost_1_34_0</strong><strong>\</strong> .................<em>The “boost root directory”</em>
|
||||
<strong>index.htm</strong> .........<em>A copy of www.boost.org starts here</em>
|
||||
<strong>boost</strong><strong>\</strong> .........................<em>All Boost Header files</em>
|
||||
<strong>lib</strong><strong>\</strong> .....................<em>precompiled library binaries</em>
|
||||
<strong>libs</strong><strong>\</strong> ............<em>Tests, .cpp</em>s<em>, docs, etc., by library</em>
|
||||
<strong>index.html</strong> ........<em>Library documentation starts here</em>
|
||||
<strong>algorithm</strong><strong>\</strong>
|
||||
<strong>any</strong><strong>\</strong>
|
||||
<strong>array</strong><strong>\</strong>
|
||||
<em>…more libraries…</em>
|
||||
<strong>status</strong><strong>\</strong> .........................<em>Boost-wide test suite</em>
|
||||
<strong>tools</strong><strong>\</strong> ...........<em>Utilities, e.g. bjam, quickbook, bcp</em>
|
||||
<strong>more</strong><strong>\</strong> ..........................<em>Policy documents, etc.</em>
|
||||
<strong>doc</strong><strong>\</strong> ...............<em>A subset of all Boost library docs</em>
|
||||
</pre>
|
||||
<div class="sidebar">
|
||||
<p class="first sidebar-title">Header Organization</p>
|
||||
<p class="pre-wrap">The organization of Boost library headers isn't entirely uniform,
|
||||
but most libraries follow a few patterns:</p>
|
||||
<ul class="pre-wrap last">
|
||||
<li><p class="first">Some older libraries and most very small libraries place all
|
||||
public headers directly into <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">\</span></tt>.</p>
|
||||
</li>
|
||||
<li><p class="first">Most libraries' public headers live in a subdirectory of
|
||||
<tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">\</span></tt>, named after the library. For example, you'll find
|
||||
the Python library's <tt class="docutils literal"><span class="pre">def.hpp</span></tt> header in</p>
|
||||
<pre class="literal-block">
|
||||
<tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">\</span></tt><tt class="docutils literal"><span class="pre">python</span></tt><tt class="docutils literal"><span class="pre">\</span></tt><tt class="docutils literal"><span class="pre">def.hpp</span></tt>.
|
||||
</pre>
|
||||
</li>
|
||||
<li><p class="first">Some libraries have an “aggregate header” in <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">\</span></tt> that
|
||||
<tt class="docutils literal"><span class="pre">#include</span></tt>s all of the library's other headers. For
|
||||
example, <a class="reference" href="../../libs/python/doc/building.html">Boost.Python</a>'s aggregate header is</p>
|
||||
<pre class="literal-block">
|
||||
<tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">\</span></tt><tt class="docutils literal"><span class="pre">python.hpp</span></tt>.
|
||||
</pre>
|
||||
</li>
|
||||
<li><p class="first">Most libraries place private headers in a subdirectory called
|
||||
<tt class="docutils literal"><span class="pre">detail</span></tt><tt class="docutils literal"><span class="pre">\</span></tt>, or <tt class="docutils literal"><span class="pre">aux_</span></tt><tt class="docutils literal"><span class="pre">\</span></tt>. Don't expect to find
|
||||
anything you can use in these directories.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<p>It's important to note the following:</p>
|
||||
<ol class="arabic" id="boost-root-directory">
|
||||
<li><p class="first">The path to the <strong>boost root directory</strong> (often <tt class="docutils literal"><span class="pre">C:\Program</span> <span class="pre">Files\boost\</span></tt><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>) is
|
||||
sometimes referred to as <tt class="docutils literal"><span class="pre">$BOOST_ROOT</span></tt> in documentation and
|
||||
mailing lists .</p>
|
||||
</li>
|
||||
<li><p class="first">To compile anything in Boost, you need a directory containing
|
||||
the <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">\</span></tt> subdirectory in your <tt class="docutils literal"><span class="pre">#include</span></tt> path. Specific steps for setting up <tt class="docutils literal"><span class="pre">#include</span></tt>
|
||||
paths in Microsoft Visual Studio follow later in this document;
|
||||
if you use another IDE, please consult your product's
|
||||
documentation for instructions.</p>
|
||||
</li>
|
||||
<li><p class="first">Since all of Boost's header files have the <tt class="docutils literal"><span class="pre">.hpp</span></tt> extension,
|
||||
and live in the <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">\</span></tt> subdirectory of the boost root, your
|
||||
Boost <tt class="docutils literal"><span class="pre">#include</span></tt> directives will look like:</p>
|
||||
<pre class="literal-block">
|
||||
#include <boost/<em>whatever</em>.hpp>
|
||||
</pre>
|
||||
<p>or</p>
|
||||
<pre class="literal-block">
|
||||
#include "boost/<em>whatever</em>.hpp"
|
||||
</pre>
|
||||
<p>depending on your religion as regards the use of angle bracket
|
||||
includes. Even Windows users can (and, for
|
||||
portability reasons, probably should) use forward slashes in
|
||||
<tt class="docutils literal"><span class="pre">#include</span></tt> directives; your compiler doesn't care.</p>
|
||||
</li>
|
||||
<li><p class="first">Don't be distracted by the <tt class="docutils literal"><span class="pre">doc</span></tt><tt class="docutils literal"><span class="pre">\</span></tt> subdirectory; it only
|
||||
contains a subset of the Boost documentation. Start with
|
||||
<tt class="docutils literal"><span class="pre">libs</span></tt><tt class="docutils literal"><span class="pre">\</span></tt><tt class="docutils literal"><span class="pre">index.html</span></tt> if you're looking for the whole enchilada.</p>
|
||||
</li>
|
||||
</ol>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id24" id="header-only-libraries" name="header-only-libraries">3 Header-Only Libraries</a></h1>
|
||||
<p>The first thing many people want to know is, “how do I build
|
||||
Boost?” The good news is that often, there's nothing to build.</p>
|
||||
<div class="admonition-nothing-to-build admonition">
|
||||
<p class="first admonition-title">Nothing to Build?</p>
|
||||
<p class="last">Most Boost libraries are <strong>header-only</strong>: they consist <em>entirely
|
||||
of header files</em> containing templates and inline functions, and
|
||||
require no separately-compiled library binaries or special
|
||||
treatment when linking.</p>
|
||||
</div>
|
||||
<p id="separate">The only Boost libraries that <em>must</em> be built separately are:</p>
|
||||
<ul class="simple">
|
||||
<li><a class="reference" href="../../libs/filesystem/index.html">Boost.Filesystem</a></li>
|
||||
<li><a class="reference" href="../../libs/iostreams/index.html">Boost.IOStreams</a></li>
|
||||
<li><a class="reference" href="../../libs/program_options/index.html">Boost.ProgramOptions</a></li>
|
||||
<li><a class="reference" href="../../libs/python/doc/building.html">Boost.Python</a></li>
|
||||
<li><a class="reference" href="../../libs/regex/index.html">Boost.Regex</a></li>
|
||||
<li><a class="reference" href="../../libs/serialization/index.html">Boost.Serialization</a></li>
|
||||
<li><a class="reference" href="../../libs/signals/index.html">Boost.Signals</a></li>
|
||||
<li><a class="reference" href="../../libs/thread/index.html">Boost.Thread</a></li>
|
||||
<li><a class="reference" href="../../libs/wave/index.html">Boost.Wave</a></li>
|
||||
</ul>
|
||||
<p>A few libraries have optional separately-compiled binaries:</p>
|
||||
<ul class="simple">
|
||||
<li><a class="reference" href="../../libs/date_time/index.html">Boost.DateTime</a> has a binary component that is only needed if
|
||||
you're using its <tt class="docutils literal"><span class="pre">to_string</span></tt>/<tt class="docutils literal"><span class="pre">from_string</span></tt> or serialization
|
||||
features, or if you're targeting Visual C++ 6.x or Borland.</li>
|
||||
<li><a class="reference" href="../../libs/graph/index.html">Boost.Graph</a> also has a binary component that is only needed if
|
||||
you intend to <a class="reference" href="../../libs/graph/doc/read_graphviz.html">parse GraphViz files</a>.</li>
|
||||
<li><a class="reference" href="../../libs/test/index.html">Boost.Test</a> can be used in “header-only” or “separately compiled”
|
||||
mode, although <strong>separate compilation is recommended for serious
|
||||
use</strong>.</li>
|
||||
</ul>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id25" id="build-a-simple-program-using-boost" name="build-a-simple-program-using-boost">4 Build a Simple Program Using Boost</a></h1>
|
||||
<p>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:</p>
|
||||
<pre class="literal-block">
|
||||
#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) << " " );
|
||||
}
|
||||
</pre>
|
||||
<p>Copy the text of this program into a file called <tt class="docutils literal"><span class="pre">example.cpp</span></tt>.</p>
|
||||
<div class="note">
|
||||
<p class="first admonition-title"><a id="command-line-tool" name="command-line-tool"><span id="command-prompt"></span>Note</a></p>
|
||||
<p class="last">To build the examples in this guide, you can use an
|
||||
Integrated Development Environment (IDE) like Visual Studio, or
|
||||
you can issue commands from the <a class="reference" href="#command-prompt">command prompt</a>. Since every
|
||||
IDE and compiler has different options and Microsoft's are by
|
||||
far the dominant compilers on Windows, we only give specific
|
||||
directions here for Visual Studio 2005 and .NET 2003 IDEs and
|
||||
their respective command prompt compilers (using the command
|
||||
prompt is a bit simpler). If you are using another compiler or
|
||||
IDE, it should be relatively easy to adapt these instructions to
|
||||
your environment.</p>
|
||||
</div>
|
||||
<div class="small sidebar">
|
||||
<p class="first sidebar-title">Command Prompt Basics</p>
|
||||
<p>In Windows, a command-line tool is invoked by typing its name,
|
||||
optionally followed by arguments, into a <em>Command Prompt</em> window
|
||||
and pressing the Return (or Enter) key.</p>
|
||||
<p>To open a generic <em>Command Prompt</em>, click the <em>Start</em> menu
|
||||
button, click <em>Run</em>, type “cmd”, and then click <em>OK</em>.</p>
|
||||
<p id="current-directory">All commands are executed within the context of a <strong>current
|
||||
directory</strong> in the filesystem. To set the current directory,
|
||||
type:</p>
|
||||
<pre class="literal-block">
|
||||
cd <em>path</em>\<em>to</em>\<em>some</em>\<em>directory</em>
|
||||
</pre>
|
||||
<p>followed by Return. For example,</p>
|
||||
<pre class="literal-block">
|
||||
cd <tt class="docutils literal"><span class="pre">C:\Program</span> <span class="pre">Files\boost\</span></tt><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>
|
||||
</pre>
|
||||
<p class="last">Long commands can be continued across several lines by typing a
|
||||
caret (<tt class="docutils literal"><span class="pre">^</span></tt>) at the end of all but the last line. Some examples
|
||||
on this page use that technique to save horizontal space.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id26" id="build-from-the-visual-studio-ide" name="build-from-the-visual-studio-ide"><span id="vs-header-only"></span>4.1 Build From the Visual Studio IDE</a></h2>
|
||||
<ul>
|
||||
<li><p class="first">From Visual Studio's <em>File</em> menu, select <em>New</em> > <em>Project…</em></p>
|
||||
</li>
|
||||
<li><p class="first">In the left-hand pane of the resulting <em>New Project</em> dialog,
|
||||
select <em>Visual C++</em> > <em>Win32</em>.</p>
|
||||
</li>
|
||||
<li><p class="first">In the right-hand pane, select <em>Win32 Console Application</em>
|
||||
(VS8.0) or <em>Win32 Console Project</em> (VS7.1).</p>
|
||||
</li>
|
||||
<li><p class="first">In the <em>name</em> field, enter “example”</p>
|
||||
</li>
|
||||
<li><p class="first">Right-click <strong>example</strong> in the <em>Solution Explorer</em> pane and
|
||||
select <em>Properties</em> from the resulting pop-up menu</p>
|
||||
</li>
|
||||
<li><p class="first">In <em>Configuration Properties</em> > <em>C/C++</em> > <em>General</em> > <em>Additional Include
|
||||
Directories</em>, enter the path to the Boost root directory, for example</p>
|
||||
<blockquote>
|
||||
<p><tt class="docutils literal"><span class="pre">C:\Program</span> <span class="pre">Files\boost\</span></tt><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt></p>
|
||||
</blockquote>
|
||||
</li>
|
||||
<li><p class="first">In <em>Configuration Properties</em> > <em>C/C++</em> > <em>Precompiled Headers</em>, change
|
||||
<em>Use Precompiled Header (/Yu)</em> to <em>Not Using Precompiled
|
||||
Headers</em>.<a class="footnote-reference" href="#pch" id="id4" name="id4"><sup>3</sup></a></p>
|
||||
</li>
|
||||
<li><p class="first">Replace the contents of the <tt class="docutils literal"><span class="pre">example.cpp</span></tt> generated by the IDE
|
||||
with the example code above.</p>
|
||||
</li>
|
||||
<li><p class="first">From the <em>Build</em> menu, select <em>Build Solution</em>.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<p>To test your application, hit the F5 key and type the following
|
||||
into the resulting window, followed by the Return key:</p>
|
||||
<pre class="literal-block">
|
||||
1 2 3
|
||||
</pre>
|
||||
<p>Then hold down the control key and press "Z", followed by the
|
||||
Return key.</p>
|
||||
<p><a class="reference" href="#errors-and-warnings"><em>skip to the next step</em></a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id27" id="or-build-from-the-command-prompt" name="or-build-from-the-command-prompt">4.2 Or, Build From the Command Prompt</a></h2>
|
||||
<p>From your computer's <em>Start</em> menu, if you are a Visual
|
||||
Studio 2005 user, select</p>
|
||||
<blockquote>
|
||||
<em>All Programs</em> > <em>Microsoft Visual Studio 2005</em>
|
||||
> <em>Visual Studio Tools</em> > <em>Visual Studio 2005 Command Prompt</em></blockquote>
|
||||
<p>or, if you're a Visual Studio .NET 2003 user, select</p>
|
||||
<blockquote>
|
||||
<em>All Programs</em> > <em>Microsoft Visual Studio .NET 2003</em>
|
||||
> <em>Visual Studio .NET Tools</em> > <em>Visual Studio .NET 2003 Command Prompt</em></blockquote>
|
||||
<p>to bring up a special <a class="reference" href="#command-prompt">command prompt</a> window set up for the
|
||||
Visual Studio compiler. In that window, set the <a class="reference" href="#current-directory">current
|
||||
directory</a> to a suitable location for creating some temporary
|
||||
files and type the following command followed by the Return key:</p>
|
||||
<pre class="literal-block">
|
||||
cl /EHsc /I <em>path\to\</em><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt> <em>path</em>\<em>to</em>\example.cpp
|
||||
</pre>
|
||||
<p>To test the result, type:</p>
|
||||
<pre class="literal-block">
|
||||
echo 1 2 3 | example
|
||||
</pre>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id28" id="errors-and-warnings" name="errors-and-warnings">4.3 Errors and Warnings</a></h2>
|
||||
<p>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.<a class="footnote-reference" href="#warnings" id="id6" name="id6"><sup>5</sup></a> <strong>Errors are another matter</strong>. If you're
|
||||
seeing compilation errors at this point in the tutorial, check to
|
||||
be sure you've copied the <a class="reference" href="#build-a-simple-program-using-boost">example program</a> correctly and that you've
|
||||
correctly identified the <a class="reference" href="#boost-root-directory">Boost root directory</a>.</p>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id29" id="prepare-to-use-a-boost-library-binary" name="prepare-to-use-a-boost-library-binary">5 Prepare to Use a Boost Library Binary</a></h1>
|
||||
<p>If you want to use any of the separately-compiled Boost libraries,
|
||||
you'll need to acquire library binaries.</p>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id30" id="install-visual-studio-2005-or-net-2003-binaries" name="install-visual-studio-2005-or-net-2003-binaries">5.1 Install Visual Studio (2005 or .NET 2003) Binaries</a></h2>
|
||||
<p>The <a class="reference" href="http://www.boost-consulting.com/download/windows">installer</a> supplied by Boost Consulting will download and
|
||||
install pre-compiled binaries into the <tt class="docutils literal"><span class="pre">lib\</span></tt> subdirectory of the
|
||||
boost root, typically <tt class="docutils literal"><span class="pre">C:\Program</span> <span class="pre">Files\boost\</span></tt><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt><tt class="docutils literal"><span class="pre">\lib\</span></tt>. If you installed
|
||||
all variants of the <a class="reference" href="../../libs/regex/index.html">Boost.Regex</a> binary, you're done with this
|
||||
step. Otherwise, please run the installer again and install them
|
||||
now.</p>
|
||||
<p><a class="reference" href="#link-your-program-to-a-boost-library"><em>skip to the next step</em></a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id31" id="or-build-and-install-binaries-from-source" name="or-build-and-install-binaries-from-source">5.2 Or, Build and Install Binaries From Source</a></h2>
|
||||
<p>If you're using an earlier version of Visual C++, or a compiler
|
||||
from another vendor, you'll need to use <a class="reference" href="../../tools/build/index.html">Boost.Build</a> to create your
|
||||
own binaries.</p>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<p><a class="reference" href="../../tools/build/index.html">Boost.Build</a> is a text-based system for developing, testing, and
|
||||
installing software. To use it, you'll need an executable called
|
||||
<tt class="docutils literal"><span class="pre">bjam</span></tt>.</p>
|
||||
<div class="section">
|
||||
<h3><a class="toc-backref" href="#id32" id="get-bjam" name="get-bjam">5.2.1 Get <tt class="docutils literal"><span class="pre">bjam</span></tt></a></h3>
|
||||
<p><tt class="docutils literal"><span class="pre">bjam</span></tt> is the <a class="reference" href="#command-line-tool">command-line tool</a> that drives the Boost Build
|
||||
system. To build Boost binaries, you'll invoke <tt class="docutils literal"><span class="pre">bjam</span></tt> from the
|
||||
Boost root.</p>
|
||||
<p>Boost provides <a class="reference" href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=72941">pre-compiled <tt class="docutils literal"><span class="pre">bjam</span></tt> executables</a> for a variety of platforms.
|
||||
Alternatively, you can build <tt class="docutils literal"><span class="pre">bjam</span></tt> yourself using <a class="reference" href="../../doc/html/jam/building.html">these
|
||||
instructions</a>.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h3><a class="toc-backref" href="#id33" id="identify-your-toolset" name="identify-your-toolset"><span id="toolset-name"></span><span id="toolset"></span>5.2.2 Identify Your Toolset</a></h3>
|
||||
<p>First, find the toolset corresponding to your compiler in the
|
||||
following table.</p>
|
||||
<table border="1" class="docutils table">
|
||||
<colgroup>
|
||||
<col width="18%" />
|
||||
<col width="33%" />
|
||||
<col width="48%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th class="head">Toolset
|
||||
Name</th>
|
||||
<th class="head">Vendor</th>
|
||||
<th class="head">Notes</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><tt class="docutils literal"><span class="pre">acc</span></tt></td>
|
||||
<td>Hewlett Packard</td>
|
||||
<td>Only very recent versions are
|
||||
known to work well with Boost</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">borland</span></tt></td>
|
||||
<td>Borland</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">como</span></tt></td>
|
||||
<td>Comeau Computing</td>
|
||||
<td>Using this toolset may
|
||||
require <a class="reference" href="../../tools/build/index.html">configuring</a> another
|
||||
toolset to act as its backend</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">cw</span></tt></td>
|
||||
<td>Metrowerks/FreeScale</td>
|
||||
<td>The CodeWarrior compiler. We
|
||||
have not tested versions of
|
||||
this compiler produced since
|
||||
it was sold to FreeScale.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">dmc</span></tt></td>
|
||||
<td>Digital Mars</td>
|
||||
<td>As of this Boost release, no
|
||||
version of dmc is known to
|
||||
handle Boost well.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">darwin</span></tt></td>
|
||||
<td>Apple Computer</td>
|
||||
<td>Apple's version of the GCC
|
||||
toolchain with support for
|
||||
Darwin and MacOS X features
|
||||
such as frameworks.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">gcc</span></tt></td>
|
||||
<td>The Gnu Project</td>
|
||||
<td>Includes support for Cygwin
|
||||
and MinGW compilers.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">hp_cxx</span></tt></td>
|
||||
<td>Hewlett Packard</td>
|
||||
<td>Targeted at the Tru64
|
||||
operating system.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">intel</span></tt></td>
|
||||
<td>Intel</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">kylix</span></tt></td>
|
||||
<td>Borland</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">msvc</span></tt></td>
|
||||
<td>Microsoft</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">qcc</span></tt></td>
|
||||
<td>QNX Software Systems</td>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">sun</span></tt></td>
|
||||
<td>Sun</td>
|
||||
<td>Only very recent versions are
|
||||
known to work well with
|
||||
Boost.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">vacpp</span></tt></td>
|
||||
<td>IBM</td>
|
||||
<td>The VisualAge C++ compiler.</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>If you have multiple versions of a particular compiler installed,
|
||||
you can append the version number to the toolset name, preceded by a
|
||||
hyphen, e.g. <tt class="docutils literal"><span class="pre">msvc-7.1</span></tt> or <tt class="docutils literal"><span class="pre">gcc-3.4</span></tt>.</p>
|
||||
<div class="note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">if you built <tt class="docutils literal"><span class="pre">bjam</span></tt> yourself, you may
|
||||
have selected a toolset name for that purpose, but that does not
|
||||
affect this step in any way; you still need to select a Boost.Build
|
||||
toolset from the table.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h3><a class="toc-backref" href="#id34" id="select-a-build-directory" name="select-a-build-directory"><span id="id11"></span><span id="build-directory"></span>5.2.3 Select a Build Directory</a></h3>
|
||||
<p><a class="reference" href="../../tools/build/index.html">Boost.Build</a> will place all intermediate files it generates while
|
||||
building into the <strong>build directory</strong>. If your Boost root
|
||||
directory is writable, this step isn't strictly necessary: by
|
||||
default Boost.Build will create a <tt class="docutils literal"><span class="pre">bin.v2/</span></tt> subdirectory for that
|
||||
purpose in your current working directory.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h3><a class="toc-backref" href="#id35" id="invoke-bjam" name="invoke-bjam">5.2.4 Invoke <tt class="docutils literal"><span class="pre">bjam</span></tt></a></h3>
|
||||
<p>Change your current directory to the Boost root directory and
|
||||
invoke <tt class="docutils literal"><span class="pre">bjam</span></tt> as follows:</p>
|
||||
<pre class="literal-block">
|
||||
bjam <strong>--build-dir=</strong><a class="reference" href="#id11"><em>build-directory</em></a> <strong>--toolset=</strong><a class="reference" href="#toolset-name"><em>toolset-name</em></a> stage
|
||||
</pre>
|
||||
<p>For example, your session might look like this:<a class="footnote-reference" href="#continuation" id="id12" name="id12"><sup>4</sup></a></p>
|
||||
<pre class="literal-block">
|
||||
C:WINDOWS> cd <tt class="docutils literal"><span class="pre">C:\Program</span> <span class="pre">Files\boost\</span></tt><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>
|
||||
<tt class="docutils literal"><span class="pre">C:\Program</span> <span class="pre">Files\boost\</span></tt><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>> bjam <strong>^</strong>
|
||||
More? <strong>--build-dir=</strong>%TEMP%\build-boost <strong>^</strong>
|
||||
More? <strong>--toolset=</strong>msvc stage
|
||||
</pre>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<p>Boost.Build will place the Boost binaries in the <tt class="docutils literal"><span class="pre">stage</span></tt><tt class="docutils literal"><span class="pre">\</span></tt>
|
||||
subdirectory of your <a class="reference" href="#build-directory">build directory</a>.</p>
|
||||
<div class="note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last"><tt class="docutils literal"><span class="pre">bjam</span></tt> is case-sensitive; it is important that all the
|
||||
parts shown in <strong>bold</strong> type above be entirely lower-case.</p>
|
||||
</div>
|
||||
<p>For a description of other options you can pass when invoking
|
||||
<tt class="docutils literal"><span class="pre">bjam</span></tt>, type:</p>
|
||||
<pre class="literal-block">
|
||||
bjam --help
|
||||
</pre>
|
||||
<p>In particular, to limit the amount of time spent building, you may
|
||||
be interested in:</p>
|
||||
<ul class="simple">
|
||||
<li>reviewing the list of library names with <tt class="docutils literal"><span class="pre">--show-libraries</span></tt></li>
|
||||
<li>limiting which libraries get built with the <tt class="docutils literal"><span class="pre">--with-</span></tt><em>library-name</em> or <tt class="docutils literal"><span class="pre">--without-</span></tt><em>library-name</em> options</li>
|
||||
<li>choosing a specific build variant by adding <tt class="docutils literal"><span class="pre">release</span></tt> or
|
||||
<tt class="docutils literal"><span class="pre">debug</span></tt> to the command line.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id36" id="expected-build-output" name="expected-build-output">5.3 Expected Build Output</a></h2>
|
||||
<p>During the process of building Boost libraries, you can expect to
|
||||
see some messages printed on the console. These may include</p>
|
||||
<ul>
|
||||
<li><p class="first">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.</p>
|
||||
</li>
|
||||
<li><p class="first">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.</p>
|
||||
</li>
|
||||
<li><p class="first">Build action messages describing what the tool is doing, which
|
||||
look something like:</p>
|
||||
<pre class="literal-block">
|
||||
<em>toolset-name</em>.c++ <em>long</em>/<em>path</em>/<em>to</em>/<em>file</em>/<em>being</em>/<em>built</em>
|
||||
</pre>
|
||||
</li>
|
||||
<li><p class="first">Compiler warnings.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id37" id="in-case-of-build-errors" name="in-case-of-build-errors">5.4 In Case of Build Errors</a></h2>
|
||||
<p>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 <a class="reference" href="../../libs/iostreams/doc/installation.html">here</a>. Install the relevant development
|
||||
packages for libz and libbz2 if you need those features. Other
|
||||
errors when building Boost libraries are cause for concern.</p>
|
||||
<p>If it seems like the build system can't find your compiler and/or
|
||||
linker, consider setting up a <tt class="docutils literal"><span class="pre">user-config.jam</span></tt> file as described
|
||||
in the <a class="reference" href="../../tools/build/index.html">Boost.Build documentation</a>. If that isn't your problem or
|
||||
the <tt class="docutils literal"><span class="pre">user-config.jam</span></tt> file doesn't work for you, please address
|
||||
questions about configuring Boost for your compiler to the
|
||||
<a class="reference" href="../../more/mailing_lists.htm#jamboost">Boost.Build mailing list</a>.</p>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id38" id="link-your-program-to-a-boost-library" name="link-your-program-to-a-boost-library">6 Link Your Program to a Boost Library</a></h1>
|
||||
<p>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 <a class="reference" href="../../libs/regex/index.html">Boost.Regex</a> library, which has a
|
||||
separately-compiled binary component.</p>
|
||||
<pre class="literal-block">
|
||||
#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;
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
<p>There are two main challenges associated with linking:</p>
|
||||
<ol class="arabic simple">
|
||||
<li>Tool configuration, e.g. choosing command-line options or IDE
|
||||
build settings.</li>
|
||||
<li>Identifying the library binary, among all the build variants,
|
||||
whose compile configuration is compatible with the rest of your
|
||||
project.</li>
|
||||
</ol>
|
||||
<div class="admonition-auto-linking admonition">
|
||||
<p class="first admonition-title">Auto-Linking</p>
|
||||
<p class="last">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.</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id39" id="link-from-within-the-visual-studio-ide" name="link-from-within-the-visual-studio-ide">6.1 Link From Within the Visual Studio IDE</a></h2>
|
||||
<p>Starting with the <a class="reference" href="#vs-header-only">header-only example project</a> we created
|
||||
earlier:</p>
|
||||
<ol class="arabic simple">
|
||||
<li>Right-click <strong>example</strong> in the <em>Solution Explorer</em> pane and
|
||||
select <em>Properties</em> from the resulting pop-up menu</li>
|
||||
<li>In <em>Configuration Properties</em> > <em>Linker</em> > <em>Additional Library
|
||||
Directories</em>, enter the path to the Boost binaries,
|
||||
e.g. <tt class="docutils literal"><span class="pre">C:\Program</span> <span class="pre">Files\boost\</span></tt><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt><tt class="docutils literal"><span class="pre">\lib\</span></tt>.</li>
|
||||
<li>From the <em>Build</em> menu, select <em>Build Solution</em>.</li>
|
||||
</ol>
|
||||
<p><a class="reference" href="#test-your-program"><em>skip to the next step</em></a></p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id40" id="or-link-from-the-command-prompt" name="or-link-from-the-command-prompt">6.2 Or, Link From the Command Prompt</a></h2>
|
||||
<p>For example, we can compile and link the above program from the
|
||||
Visual C++ command-line by simply adding the <strong>bold</strong> text below to
|
||||
the command line we used earlier, assuming your Boost binaries are
|
||||
in <tt class="docutils literal"><span class="pre">C:\Program</span> <span class="pre">Files\boost\</span></tt><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt><tt class="docutils literal"><span class="pre">\lib</span></tt>:</p>
|
||||
<pre class="literal-block">
|
||||
cl /EHsc /I <em>path\to\</em><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt> example.cpp <strong>^</strong>
|
||||
<strong>/link /LIBPATH:</strong> <strong>C:\Program Files\boost\</strong><strong>boost_1_34_0</strong><strong>\lib</strong>
|
||||
</pre>
|
||||
<div class="note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p>If—like Visual C++—your compiler supports auto-linking,
|
||||
you can probably ignore the next section.</p>
|
||||
<p class="last"><a class="reference" href="#test-your-program"><em>skip to the next step</em></a></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id41" id="library-naming" name="library-naming">6.3 Library Naming</a></h2>
|
||||
<div class="note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p>If, like Visual C++, your compiler supports auto-linking,
|
||||
you can probably <a class="reference" href="#test-your-program"><em>skip to the next step</em></a>.</p>
|
||||
<blockquote class="last">
|
||||
</blockquote>
|
||||
</div>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<p>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,
|
||||
<tt class="docutils literal"><span class="pre">libboost_regex-vc71-mt-d-1_34.lib</span></tt> can be broken down into the
|
||||
following elements:</p>
|
||||
<dl class="docutils">
|
||||
<dt><tt class="docutils literal"><span class="pre">lib</span></tt></dt>
|
||||
<dd><em>Prefix</em>: except on Microsoft Windows, every Boost library
|
||||
name begins with this string. On Windows, only ordinary static
|
||||
libraries use the <tt class="docutils literal"><span class="pre">lib</span></tt> prefix; import libraries and DLLs do
|
||||
not.<a class="footnote-reference" href="#distinct" id="id18" name="id18"><sup>6</sup></a></dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">boost_regex</span></tt></dt>
|
||||
<dd><em>Library name</em>: all boost library filenames begin with <tt class="docutils literal"><span class="pre">boost_</span></tt>.</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">-vc71</span></tt></dt>
|
||||
<dd><em>Toolset tag</em>: identifies the toolset and version used to build
|
||||
the binary.</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">-mt</span></tt></dt>
|
||||
<dd><em>Threading tag</em>: indicates that the library was
|
||||
built with multithreading support enabled. Libraries built
|
||||
without multithreading support can be identified by the absence
|
||||
of <tt class="docutils literal"><span class="pre">-mt</span></tt>.</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">-d</span></tt></dt>
|
||||
<dd><p class="first"><em>ABI tag</em>: encodes details that affect the library's
|
||||
interoperability with other compiled code. For each such
|
||||
feature, a single letter is added to the tag:</p>
|
||||
<blockquote>
|
||||
<table border="1" class="docutils table">
|
||||
<colgroup>
|
||||
<col width="6%" />
|
||||
<col width="94%" />
|
||||
</colgroup>
|
||||
<thead valign="bottom">
|
||||
<tr><th class="head">Key</th>
|
||||
<th class="head">Use this library when:</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody valign="top">
|
||||
<tr><td><tt class="docutils literal"><span class="pre">s</span></tt></td>
|
||||
<td>linking statically to the C++ standard library and compiler runtime support
|
||||
libraries.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">g</span></tt></td>
|
||||
<td>using debug versions of the standard and runtime support libraries.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">y</span></tt></td>
|
||||
<td>using a special <a class="reference" href="../../libs/python/doc/building.html#variants">debug build of Python</a>.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">d</span></tt></td>
|
||||
<td>building a debug version of your code.<a class="footnote-reference" href="#debug-abi" id="id19" name="id19"><sup>7</sup></a></td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">p</span></tt></td>
|
||||
<td>using the STLPort standard library rather than the default one supplied with
|
||||
your compiler.</td>
|
||||
</tr>
|
||||
<tr><td><tt class="docutils literal"><span class="pre">n</span></tt></td>
|
||||
<td>using STLPort's deprecated “native iostreams” feature.<a class="footnote-reference" href="#native" id="id20" name="id20"><sup>8</sup></a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</blockquote>
|
||||
<p class="last">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 in “native iostreams” mode,
|
||||
the tag would be: <tt class="docutils literal"><span class="pre">-sgdpn</span></tt>. If none of the above apply, the
|
||||
ABI tag is ommitted.</p>
|
||||
</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">-1_34</span></tt></dt>
|
||||
<dd><em>Version tag</em>: the full Boost release number, with periods
|
||||
replaced by underscores. For example, version 1.31.1 would be
|
||||
tagged as "-1_31_1".</dd>
|
||||
<dt><tt class="docutils literal"><span class="pre">.lib</span></tt></dt>
|
||||
<dd><em>Extension</em>: determined according to the operating system's usual
|
||||
convention. On most *nix platforms the extensions are <tt class="docutils literal"><span class="pre">.a</span></tt>
|
||||
and <tt class="docutils literal"><span class="pre">.so</span></tt> for static libraries (archives) and shared libraries,
|
||||
respectively. On Windows, <tt class="docutils literal"><span class="pre">.dll</span></tt> indicates a shared library
|
||||
and—except for static libraries built by <tt class="docutils literal"><span class="pre">gcc</span></tt> toolset, whose
|
||||
names always end in <tt class="docutils literal"><span class="pre">.a``—</span> <span class="pre">``.lib</span></tt> indicates a static or import
|
||||
library. Where supported by *nix toolsets, 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.</dd>
|
||||
</dl>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
<div class="section">
|
||||
<h2><a class="toc-backref" href="#id42" id="test-your-program" name="test-your-program">6.4 Test Your Program</a></h2>
|
||||
<p>To test our subject extraction, we'll filter the following text
|
||||
file. Copy it out of your browser and save it as <tt class="docutils literal"><span class="pre">jayne.txt</span></tt>:</p>
|
||||
<pre class="literal-block">
|
||||
To: George Shmidlap
|
||||
From: Rita Marlowe
|
||||
Subject: Will Success Spoil Rock Hunter?
|
||||
---
|
||||
See subject.
|
||||
</pre>
|
||||
<p>Now, in a <a class="reference" href="#command-prompt">command prompt</a> window, type:</p>
|
||||
<pre class="literal-block">
|
||||
<em>path</em>\<em>to</em>\<em>compiled</em>\example < <em>path</em>\<em>to</em>\jayne.txt
|
||||
</pre>
|
||||
<p>The program should respond with the email subject, “Will Success
|
||||
Spoil Rock Hunter?”</p>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<h1><a class="toc-backref" href="#id43" id="conclusion-and-further-resources" name="conclusion-and-further-resources">7 Conclusion and Further Resources</a></h1>
|
||||
<p>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 <a class="reference" href="../../more/mailing_lists.htm#users">Boost Users'
|
||||
mailing list</a>.</p>
|
||||
<ul class="simple">
|
||||
<li><a class="reference" href="../tools/build/v2">Boost.Build reference manual</a></li>
|
||||
<li><a class="reference" href="../../tools/jam/index.html">Boost.Jam reference manual</a></li>
|
||||
<li><a class="reference" href="../../more/mailing_lists.htm#users">Boost Users' mailing list</a></li>
|
||||
<li><a class="reference" href="../../more/mailing_lists.htm#jamboost">Boost.Build mailing list</a></li>
|
||||
<li><a class="reference" href="http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Boost.Build_V2">Boost.Build Wiki</a></li>
|
||||
<li><a class="reference" href="../../libs/index.html">Index of all Boost library documentation</a></li>
|
||||
</ul>
|
||||
<div class="admonition-onward admonition">
|
||||
<p class="first admonition-title">Onward</p>
|
||||
<blockquote class="epigraph last">
|
||||
<p>Good luck, and have fun!</p>
|
||||
<p class="attribution">—the Boost Developers</p>
|
||||
</blockquote>
|
||||
</div>
|
||||
<hr class="docutils" />
|
||||
<table class="docutils footnote" frame="void" id="zip" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id2" name="zip">[1]</a></td><td>If you prefer not to download executable programs,
|
||||
download <a class="reference" href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041&release_id=376197"><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt><tt class="docutils literal"><span class="pre">.zip</span></tt></a> and use an external tool to decompress
|
||||
it. We don't recommend using Windows' built-in decompression as
|
||||
it can be painfully slow for large archives.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="installer-src" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a name="installer-src">[2]</a></td><td>If you used the <a class="reference" href="http://www.boost-consulting.com/download/windows">installer</a> from Boost
|
||||
Consulting and deselected “Source and Documentation” (it's
|
||||
selected by default), you won't see the <tt class="docutils literal"><span class="pre">libs/</span></tt> subdirectory.
|
||||
That won't affect your ability to use precompiled binaries, but
|
||||
you won't be able to rebuild libraries from scratch.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="pch" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id4" name="pch">[3]</a></td><td>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.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="continuation" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id12" name="continuation">[4]</a></td><td>In this example, the caret character <tt class="docutils literal"><span class="pre">^</span></tt> is a
|
||||
way of continuing the command on multiple lines. The command
|
||||
prompt responds with <tt class="docutils literal"><span class="pre">More?</span></tt> to prompt for more input. Feel
|
||||
free to omit the carets and subsequent newlines; we used them so
|
||||
the example would fit on a page of reasonable width.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<table class="docutils footnote" frame="void" id="warnings" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id6" name="warnings">[5]</a></td><td>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.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="distinct" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id18" name="distinct">[6]</a></td><td>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.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="debug-abi" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id19" name="debug-abi">[7]</a></td><td>These libraries were compiled without optimization
|
||||
or inlining, with full debug symbols enabled, and without
|
||||
<tt class="docutils literal"><span class="pre">NDEBUG</span></tt> <tt class="docutils literal"><span class="pre">#define</span></tt>d. All though 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.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table class="docutils footnote" frame="void" id="native" rules="none">
|
||||
<colgroup><col class="label" /><col /></colgroup>
|
||||
<tbody valign="top">
|
||||
<tr><td class="label"><a class="fn-backref" href="#id20" name="native">[8]</a></td><td>This feature of STLPort is deprecated because it's
|
||||
impossible to make it work transparently to the user; we don't
|
||||
recommend it.</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<!-- This file contains all the definitions that need to be updated -->
|
||||
<!-- for each new release of Boost. -->
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
|
||||
<!-- Software License, Version 1.0. (See accompanying -->
|
||||
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
315
getting_started/windows.rst
Normal file
315
getting_started/windows.rst
Normal file
@ -0,0 +1,315 @@
|
||||
.. Copyright David Abrahams 2006. Distributed under the Boost
|
||||
.. Software License, Version 1.0. (See accompanying
|
||||
.. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
=======================================
|
||||
|(logo)|__ Getting Started on Windows
|
||||
=======================================
|
||||
|
||||
.. |(logo)| image:: ../../boost.png
|
||||
:alt: Boost
|
||||
:class: boost-logo
|
||||
|
||||
__ ../../index.htm
|
||||
|
||||
.. section-numbering::
|
||||
|
||||
.. Admonition:: 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.
|
||||
|
||||
.. _`Getting Started on Unix Variants`: unix-variants.html
|
||||
.. _Cygwin: http://www.cygwin.com
|
||||
.. _MinGW: http://mingw.org
|
||||
|
||||
.. Contents:: Index
|
||||
|
||||
Get Boost
|
||||
=========
|
||||
|
||||
The easiest way to get a copy of Boost is to use the `installer`_
|
||||
provided by `Boost Consulting`_. We especially recommend this
|
||||
method if you use Microsoft Visual Studio .NET 2003 or Microsoft
|
||||
Visual Studio 2005, because the installer can download and install
|
||||
precompiled library binaries, saving you the trouble of building
|
||||
them yourself. To complete this tutorial, you'll need to at least
|
||||
install the Boost.Regex_ binaries when given the option.
|
||||
|
||||
.. _installer: http://www.boost-consulting.com/download/windows
|
||||
.. _Boost Consulting: http://www.boost-consulting.com
|
||||
|
||||
If you're using an earlier version of Visual Studio or some other
|
||||
compiler, or if you prefer to build everything yourself, you can
|
||||
download |boost.exe|_ and run it to install a complete Boost
|
||||
distribution. [#zip]_
|
||||
|
||||
.. |boost.exe| replace:: |boost_ver|\ ``.exe``
|
||||
|
||||
.. _`boost.exe`: `sf-download`_
|
||||
|
||||
.. include:: detail/distro.rst
|
||||
|
||||
.. include:: detail/header-only.rst
|
||||
|
||||
.. include:: detail/build-simple-head.rst
|
||||
|
||||
.. _`command prompt`:
|
||||
.. _`command-line tool`:
|
||||
|
||||
.. Note:: To build the examples in this guide, you can use an
|
||||
Integrated Development Environment (IDE) like Visual Studio, or
|
||||
you can issue commands from the `command prompt`_. Since every
|
||||
IDE and compiler has different options and Microsoft's are by
|
||||
far the dominant compilers on Windows, we only give specific
|
||||
directions here for Visual Studio 2005 and .NET 2003 IDEs and
|
||||
their respective command prompt compilers (using the command
|
||||
prompt is a bit simpler). If you are using another compiler or
|
||||
IDE, it should be relatively easy to adapt these instructions to
|
||||
your environment.
|
||||
|
||||
.. sidebar:: Command Prompt Basics
|
||||
:class: small
|
||||
|
||||
In Windows, a command-line tool is invoked by typing its name,
|
||||
optionally followed by arguments, into a *Command Prompt* window
|
||||
and pressing the Return (or Enter) key.
|
||||
|
||||
To open a generic *Command Prompt*, click the *Start* menu
|
||||
button, click *Run*, type “cmd”, and then click *OK*.
|
||||
|
||||
.. _current directory:
|
||||
|
||||
All commands are executed within the context of a **current
|
||||
directory** in the filesystem. To set the current directory,
|
||||
type:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
cd *path*\ \\\ *to*\ \\\ *some*\ \\\ *directory*
|
||||
|
||||
followed by Return. For example,
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
cd |default-root|
|
||||
|
||||
Long commands can be continued across several lines by typing a
|
||||
caret (``^``) at the end of all but the last line. Some examples
|
||||
on this page use that technique to save horizontal space.
|
||||
|
||||
.. _vs-header-only:
|
||||
|
||||
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 example
|
||||
|
||||
|default-root|
|
||||
|
||||
* In *Configuration Properties* > *C/C++* > *Precompiled Headers*, change
|
||||
*Use Precompiled Header (/Yu)* to *Not Using Precompiled
|
||||
Headers*. [#pch]_
|
||||
* 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.
|
||||
|
||||
|next|__
|
||||
|
||||
__ `Errors and Warnings`_
|
||||
|
||||
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:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
cl /EHsc /I |root| *path*\ \\\ *to*\ \\example.cpp
|
||||
|
||||
To test the result, type:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
echo 1 2 3 | example
|
||||
|
||||
.. include:: detail/errors-and-warnings.rst
|
||||
|
||||
.. include:: detail/binary-head.rst
|
||||
|
||||
Install Visual Studio (2005 or .NET 2003) Binaries
|
||||
--------------------------------------------------
|
||||
|
||||
The installer_ supplied by Boost Consulting will download and
|
||||
install pre-compiled binaries into the ``lib\`` subdirectory of the
|
||||
boost root, typically |default-root|\ ``\lib\``. If you installed
|
||||
all variants of the Boost.Regex_ binary, you're done with this
|
||||
step. Otherwise, please run the installer again and install them
|
||||
now.
|
||||
|
||||
|next|__
|
||||
|
||||
__ `Link Your Program to a Boost Library`_
|
||||
|
||||
Or, Build and Install 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.
|
||||
|
||||
.. include:: detail/build-from-source-head.rst
|
||||
|
||||
For example, your session might look like this: [#continuation]_
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
C:\WINDOWS> cd |default-root|
|
||||
|default-root|> bjam **^**
|
||||
More? **--build-dir=**\ %TEMP%\\build-boost **^**
|
||||
More? **--toolset=**\ msvc stage
|
||||
|
||||
.. include:: detail/build-from-source-tail.rst
|
||||
|
||||
.. include:: detail/link-head.rst
|
||||
|
||||
.. Admonition:: 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.
|
||||
|
||||
Link From Within the Visual Studio IDE
|
||||
--------------------------------------
|
||||
|
||||
Starting with the `header-only example project`__ we created
|
||||
earlier:
|
||||
|
||||
__ vs-header-only_
|
||||
|
||||
1. Right-click **example** in the *Solution Explorer* pane and
|
||||
select *Properties* from the resulting pop-up menu
|
||||
2. In *Configuration Properties* > *Linker* > *Additional Library
|
||||
Directories*, enter the path to the Boost binaries,
|
||||
e.g. |default-root|\ ``\lib\``.
|
||||
3. From the *Build* menu, select *Build Solution*.
|
||||
|
||||
|next|__
|
||||
|
||||
__ `Test Your Program`_
|
||||
|
||||
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 |default-root|\ ``\lib``:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
cl /EHsc /I |root| example.cpp **^**
|
||||
**/link /LIBPATH:** |default-root-bold|\ **\\lib**
|
||||
|
||||
|
||||
.. Note:: If—like Visual C++—your compiler supports auto-linking,
|
||||
you can probably ignore the next section.
|
||||
|
||||
|next|__
|
||||
|
||||
__ `Test Your Program`_
|
||||
|
||||
Library Naming
|
||||
--------------
|
||||
|
||||
.. Note:: If, like Visual C++, your compiler supports auto-linking,
|
||||
you can probably |next|__.
|
||||
|
||||
__ `Test Your Program`_
|
||||
|
||||
.. include:: detail/library-naming.rst
|
||||
|
||||
.. include:: detail/test-head.rst
|
||||
|
||||
Now, in a `command prompt`_ window, type:
|
||||
|
||||
.. parsed-literal::
|
||||
|
||||
*path*\ \\\ *to*\ \\\ *compiled*\ \\example < *path*\ \\\ *to*\ \\\ jayne.txt
|
||||
|
||||
The program should respond with the email subject, “Will Success
|
||||
Spoil Rock Hunter?”
|
||||
|
||||
.. include:: detail/conclusion.rst
|
||||
|
||||
------------------------------
|
||||
|
||||
.. [#zip] If you prefer not to download executable programs,
|
||||
download |boost.zip|_ and use an external tool to decompress
|
||||
it. We don't recommend using Windows' built-in decompression as
|
||||
it can be painfully slow for large archives.
|
||||
|
||||
.. [#installer-src] If you used the installer_ from Boost
|
||||
Consulting and deselected “Source and Documentation” (it's
|
||||
selected by default), you won't see the ``libs/`` subdirectory.
|
||||
That won't affect your ability to use precompiled binaries, but
|
||||
you won't be able to rebuild libraries from scratch.
|
||||
|
||||
.. [#pch] 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.
|
||||
|
||||
.. [#continuation] In this example, the caret character ``^`` is a
|
||||
way of continuing the command on multiple lines. The command
|
||||
prompt responds with ``More?`` to prompt for more input. Feel
|
||||
free to omit the carets and subsequent newlines; we used them so
|
||||
the example would fit on a page of reasonable width.
|
||||
|
||||
.. |boost.zip| replace:: |boost_ver|\ ``.zip``
|
||||
|
||||
.. _`boost.zip`: `sf-download`_
|
||||
|
||||
|
||||
.. include:: detail/common-footnotes.rst
|
||||
.. include:: detail/release-variables.rst
|
||||
.. include:: detail/common-windows.rst
|
||||
.. include:: detail/links.rst
|
Loading…
Reference in New Issue
Block a user