Cover | Table of Contents
www.mingw.org, and follow the link to the
MinGW download page. Download the latest version of the MinGW
installation program, which should be named
MinGW-<version>.exe.PATH environment variable so that you can
specify these tools on the command line by their simple names rather
than by their full pathnames.www.cygwin.com, and follow the link
InstallCygwin Now to download
the Cygwin installation program. Next, run the installation program.
It will ask you to make a series of choices, such as where Cygwin
should be installed.hello.cpp
#include <iostream>
int main()
{
std::cout << "Hello, World!\n";
}
|
Toolset
|
Script
|
|---|---|
|
Visual C++
|
vcvars32.bat
|
|
Intel (Windows)
|
iclvars.bat
|
|
Intel (Linux)
|
iccvars.sh or iccvars.csh
|
|
Metrowerks (Mac OS X)
|
mwvars.sh or mwvars.csh
|
|
Metrowerks (Windows)
|
cwenv.bat
|
|
Comeau
|
Same as the backend toolset
|
|
Toolset
|
Command line
|
|---|---|
|
GCC (Unix)Intel (Linux)Comeau (Unix)
|
ar ru libjohnpaul.a john.o
paul.o
johnpaul.oranlib
libjohnpaul.a
|
|
GCC (Windows)
|
ar ru libjohnpaul.a john.o
paul.o
johnpaul.o
|
|
Visual C++Comeau (with Visual C++)
|
lib -nologo -out:libjohnpaul.lib john.obj
paul.obj
johnpaul.obj
|
|
Intel (Windows)
|
xilib -nologo /out:libjohnpaul.lib john.obj
paul.obj
johnpaul.obj
|
GEORGERINGO_DLL. If you're
building a third-party library, the installation instructions should
tell you what macros to define.|
Toolset
|
Command line
|
|---|---|
|
GCC
|
g++ -shared -fPIC -o libgeorgeringo.so george.o
ringo.o georgeringo.o
|
|
GCC (Mac OS X) |
|
Toolset
|
Option
|
|---|---|
|
All
|
-I<directory>
|
www.boost.org/boost-build2 or follow these
steps:www.boost.org, and
follow the Download link to Boost's
SourceForge download area.PATH environment variable.BOOST_BUILD_PATH to the Boost. Build root
directory. If you downloaded the package boost
in step 1, the root directory is the subdirectory
tools/build/v2 of your Boost installation;
otherwise, it is the directory boost-build.exe
rule to declare an executable target, specifying your
.cpp file as a source.
Next, invoke the install rule, specifying the
executable target name and the location where you want the install
directory. Finally, run bjam to build your
program.# jamfile for project hello exe hello : hello.cpp ; install dist : hello : <location>. ;
> bjam hello
> bjam dist
location property, which in this case is the
current directory.lib rule
to declare a library target, specifying your
.cpp files as sources and the property
<link>static as a requirement. Add a usage
requirement of the form
<include>path to
specify the library's include directory, i.e., the
directory with respect to which include directives
for library headers should be resolved. You may need to add one or
more requirements of the form
<include>path to
tell the compiler where to search for included headers. Finally, run
bjam from the directory containing
Jamroot, as described in Recipe 1.7.# Jamfile for project libjohnpaul
lib libjohnpaul
: # sources
john.cpp paul.cpp johnpaul.cpp
: # requirements
<link>static
: # default-build
: # usage-requirements
<include>..
;
> bjam libjohnpaul
lib rule is used to declare a target
representing a static or dynamic library. It takes the same form as
the exe rule, as illustrated in Example 1-9. The usage requirement
<include>.. frees projects that depend on
your library from having to explicitly specify your
library's include directory in their requirements.
The requirement <link>static specifies that
your target should always be built as a static library. If you want
the freedom to build a library target either as static or as dynamic,
you can omit the requirement <link>static.
Whether the library is built as static or dynamic can then be
specified on the command line, or in the requirements of a target
that depends on the library target. For example, if the requirement
lib rule to
declare a library target, specifying your .cpp
files as sources and the properties <link>shared
as a requirement. Add a usage requirement of the form
<include>path to
specify the library's include directory, i.e., the
directory with respect to which include directives
for library headers should be resolved. If your source files include
headers from other libraries, you may need to add several
requirements of the form
<include>path to
tell the compiler where to search for included headers. You may also
need to add one or more requirements of the form
<define>symbol to
ensure that your dynamic library's symbols will be
exported using _ _declspec(dllexport) on Windows.
Finally, run bjam from the directory containing
Jamroot, as described in Recipe 1.7.# Jamfile for project georgringo
lib libgeorgeringo
: # sources
george.cpp ringo.cpp georgeringo.cpp
: # requirements
<link>shared
<define>GEORGERINGO_DLL
: # default-build
: # usage-requirements
<include>..
;
> bjam libgeorgeringo
lib rule is used
to declare a target representing a static or dynamic library. The
usage requirement <include>.. frees projects
which depend on your library from having to explicitly specify your
library's include directory in their requirements.
The requirement exe rule to declare an executable target. Specify
your .cpp files and the library targets on which
the executable depends as sources. Also, add properties of the form
<include>path as
sources, if necessary, to tell the compiler where to search for
library headers.install rule, specifying the properties
<install-dependencies>on,
<install-type>EXE, and
<install-type>SHARED_LIB as requirements.# Jamfile for project hellobeatles
exe hellobeatles
: # sources
../johnpaul//libjohnpaul
../georgeringo//libgeorgeringo
hellobeatles.cpp
;
install dist
: # sources
hellobeatles
: # requirements
<install-dependencies>on
<install-type>EXE
<install-type>SHARED_LIB
<location>.
;
> bjam hellobeatles
hellobeatles depends, and then builds the target
hellobeatles. Finally, enter:> bjam dist
_
_declspec(dllexport).http://www.mingw.org, go to the MinGW
download area and download the latest stable version of
Return to C++ Cookbook