[C++-sig] Building "hello world" with Boost.Python

k k ralvek at yahoo.it
Tue Sep 30 14:20:25 CEST 2008

Correction: the 2 output files are hello.o and hello_ext.lib

----- Messaggio originale -----
Da: k k <ralvek at yahoo.it>
A: c++-sig at python.org
Inviato: Martedì 30 settembre 2008, 14:17:56
Oggetto: Building "hello world" with Boost.Python

Hi all,
i want to use a C++ dll (containing overloaded functions) with Python.
I'm trying to use Boost.Python.
I dowloaded it and now I'm doing the hello world tutorial situated in the boost installation folder in \libs\python\example\tutorial
I got also bjam and configured it to work with gcc and python 2.5.
This is the hello.cpp file to export:

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>

char const* greet()
   return "hello, world";

    using namespace boost::python;
    def("greet", greet);

I use this Jamroot file (that is in the same folder as hello.cpp):

# 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)

# Specify the path to the Boost project.  If you move this project
# adjust this path to refer to the Boost root directory.

use-project boost
    : ../../../.. ;

# Set up the project-wide requirements that everything uses the
# boost_python library from the project whose global ID is
# /boost/python.

 : requirements <library>/boost/python//boost_python ;

# Declare the three extension modules.  You can specify multiple
# source files after the colon separated by spaces.

python-extension hello_ext : hello.cpp ;

# A little "rule" (function) to clean up the syntax of declaring tests
# of these extension modules.

local rule run-test ( test-name : sources + )
        import testing ;
        testing.make-test run-pyd : $(sources) : : $(test-name) ;

# Declare test targets

run-test hello : hello_ext hello.py ;

In the Jamroot file i changed only this:

use-project boost
  : ../../../.. ;with this(the boost root folder on on my disk):

use-project boost
  : C:/boost/boost_1_35_0 ;When i run bjam it seams that it builds well, only with some warning, but without any error.
In the tutorial they say that if all is well i should now have built the DLLs.
But the only things in there are 2 files: hello.o and hello.lib
I can't use these as python modules, how can i get the DLL? and the .pyd?

Thanks in advance.

Do You Yahoo!?
Poco spazio e tanto spam? Yahoo! Mail ti protegge dallo spam e ti da tanto spazio gratuito per i tuoi file e i messaggi 

      Scopri il blog di Yahoo! Mail:
Trucchi, novità e la tua opinione.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080930/34933da7/attachment.htm>

More information about the Cplusplus-sig mailing list