| Home | Libraries | People | FAQ | More

## Building Hello World

## From Start To Finish

Now the first thing you'd want to do is to build the Hello World module and try it for yourself in Python. In this section, we will outline the steps necessary to achieve that. We will use the build tool that comes bundled with every boost distribution: bjam.

| Note
Building without bjam Besides bjam, there are of course other ways to get your module built. What's written here should not be taken as "the one and only way". There are of course other build tools apart from `bjam`. Take note however that the preferred build tool for Boost.Python is bjam. There are so many ways to set up the build incorrectly. Experience shows that 90% of the "I can't build Boost.Python" problems come from people who had to use a different tool.

We will skip over the details. Our objective will be to simply create the hello world module and run it in Python. For a complete reference to building Boost.Python, check out: building.html. After this brief bjam tutorial, we should have built the DLLs and run a python program using the extension.

The tutorial example can be found in the directory: `libs/python/example/tutorial`. There, you can find:

- hello.cpp
- hello.py
- Jamroot

The `hello.cpp` file is our C++ hello world example. The `Jamroot` is a minimalist bjam script that builds the DLLs for us. Finally, `hello.py` is our Python program that uses the extension in `hello.cpp`.

Before anything else, you should have the bjam executable in your boost directory or somewhere in your path such that `bjam` can be executed in the command line. Pre-built Boost.Jam executables are available for most platforms. The complete list of Bjam executables can be found here.

## Let's Jam!

Here is our minimalist Jamroot file. Simply copy the file and tweak `use-project boost` to where your boost root directory is and your OK.

The comments contained in the Jamrules file above should be sufficient to get you going.

## Running bjam

bjam is run using your operating system's command line interpreter.

> Start it up.

A file called user-config.jam in your home directory is used to configure your tools. In Windows, your home directory can be found by typing:

    ECHO %HOMEDRIVE%%HOMEPATH%

into a command prompt window. Your file should at least have the rules for your compiler and your python installation. A specific example of this on Windows would be:

    #  MSVC configuration
    using msvc : 8.0 ;

    #  Python configuration
    using python : 2.4 : C:/dev/toolsPython ;

The first rule tells Bjam to use the MSVC 8.0 compiler and associated tools. The second rule provides information on Python, its version and where it is located. The above assumes that the Python installation is in `C:/dev/tools/Python/`. If you have one fairly "standard" python installation for your platform, you might not need to do this.

Now we are ready... Be sure to `cd` to `libs/python/example/tutorial` where the tutorial `"hello.cpp"` and the `"Jamroot"` is situated.

Finally:

    bjam

It should be building now:

    cd C:\dev\boost\libs\python\example\tutorial
    bjam
    ...patience...
    ...found 1101 targets...
    ...updating 35 targets...

And so on... Finally:

    Creating library path-to-boost_python.dll
       Creating library path-to-'''hello_ext'''.exp
    **passed** ... hello.test
    ...updated 35 targets...

Or something similar. If all is well, you should now have built the DLLs and run the Python program.

| Note
Starting from Boost 1.35, bjam erases the generated executables (e.g. pyd file). To keep bjam from doing that, pass --preserve-test-targets to bjam.

> There you go... Have fun!