[C++-sig] Re: Embedding Tutorial

William Trenker wtrenker at hotmail.com
Thu Dec 19 16:55:06 CET 2002


Here's my simple embedding example, cleaned up as suggested and tested.  
I've also included the Jamfile I used.  Any further suggestions or 
improvements are very welcome.

Thanks for the input,
Bill

------------------------------------------------------------embed.cpp------------------------------------------

#include <boost/python.hpp>
#include <iostream>

using namespace boost::python;

int main(int argc, char** argv) {
   Py_Initialize();
   handle<> main_module( borrowed(PyImport_AddModule("__main__")) );
   handle<> main_namespace( borrowed(PyModule_GetDict(main_module.get())) );
   handle<> h_result( PyRun_String("1 + 1",
           Py_eval_input, main_namespace.get(), main_namespace.get()) );
   object o_result(h_result);
   int i_result = extract<int>(o_result);
   cout << "result = " << i_result << endl;
   //Py_Finalize();  AVOID (for now)
   return 0;
};

------------------------------------------------------------Jamfile---------------------------------------------------

project-root ;

BOOST_SO_PATH = 
/root/cvsroot/boost/libs/python/build/bin/libboost_python.so/gcc/debug/runtime-link-dynamic/shared-linkable-true 
;

SEARCH on python.jam = $(BOOST_BUILD_PATH) ;
include python.jam ;

exe embed : embed.cpp
  : # requirements
    $(PYTHON_PROPERTIES)
    <library-path>$(PYTHON_LIB_PATH)
    <find-library>$(PYTHON_EMBEDDED_LIBRARY)
    <library-path>$(BOOST_SO_PATH) <find-library>boost_python
;

------------------------------------------------------------------------------------------------------------------------------------

ps: The Jamfile template the Dave sent me had the first line like this:

exe embed : embed.cpp <dll>../boost/boost_python

but that doesn't work for me because I've set this little project up as a 
stand-alone (for the experience of doing so).  The best I could come up with 
is what you see above.


_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus





More information about the Cplusplus-sig mailing list