Mail Archives: cygwin/2001/08/06/10:04:36
------=_NextPart_000_0034_01C11E5E.E65E8DC0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Peter Bienstman writes:
>
>> If you can refer me to a self contained (i.e. not dependent on other
>> libraries, etc.) Python C++ extension, then I'm willing to fiddle around
>> with it.
>
>Attached are a simple C++ file convert.cpp and a makefile. The Python
>extension does however require the Boost Python Library
>(www.boost.org), a
>C++ system to create Python extension modules.
>
>The linking fails with errors like:
>
>convert.o(.complex<double>
>boost::python::detail::text$complex_from_python<double>(_object *,
>boost::python::type<double>)+0x10):convert.cpp: undefined reference to
>`PyInt_Type'
>../
>/users/pbienst/tmp/boost_cvs/libs/python/src/libboost_python.a(
>extension_cla
>ss.o)(.text+0x3ad):extension_class.cpp: undefined reference to
>`PyExc_RuntimeError'
>...
>
>These are symbols which I suppose must be in libpython2.1.
Try the attached Makefiles
The second Makefile goes in
$BOOST / libs / python / build
then cd into above directory and
% make
then to make sure things are working < well almost >
% cd ../test
% python doctest.py -v
< I get 52 passed and 1 failure on above >
then try making your test program
FYI --
I have Cygwin mounted at '/'
and $BOOST at '/src/boost'
adjust Makefiles according to your system
I also am using the latest Cygwin snapshot
and a locally compiled Python 2.1
< neither probably matters >
Cheers
Norman Vine
------=_NextPart_000_0034_01C11E5E.E65E8DC0
Content-Type: application/octet-stream;
name="Makefile"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="Makefile"
# location of the Python header files
PYTHON = /usr/include/python2.1
# location of the Boost Python include files and library
BOOST_INC = /src/boost
BOOST_LIB = ./
convert.dll: convert.o
g++ -shared -Wl,--enable-auto-image-base,--export-dynamic \
convert.o -L$(BOOST_LIB) -lboost_python \
-L/usr/local/lib/python2.1/config -lpython2.1 \
-o convert.dll
convert.o: convert.cpp
g++ -DUSE_DL_IMPORT -I$(PYTHON) -I$(BOOST_INC) -c convert.cpp
clean:
rm -f *.o *.dll *.a *~ core
------=_NextPart_000_0034_01C11E5E.E65E8DC0
Content-Type: text/plain;
name="convert.cpp"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="convert.cpp"
#include <iostream>=0A=
#include "boost/python/class_builder.hpp"=0A=
=0A=
using namespace boost::python;=0A=
=0A=
struct Expression { Expression() {} };=0A=
=0A=
struct Term =0A=
{=0A=
Term() {}=0A=
Term(const Expression&) {}=0A=
};=0A=
=0A=
void f(const Term& t) {}=0A=
=0A=
struct A { A(const Term&) {} };=0A=
=0A=
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE=0A=
=0A=
PyObject* to_python(const Expression& e)=0A=
{=0A=
return to_python(Term(e));=0A=
}=0A=
=0A=
BOOST_PYTHON_END_CONVERSION_NAMESPACE=0A=
=0A=
BOOST_PYTHON_MODULE_INIT(convert)=0A=
{=0A=
try=0A=
{=0A=
=0A=
module_builder convert("convert");=0A=
=0A=
class_builder<Term> Term_(convert, "Term");=0A=
Term_.def(constructor<>());=0A=
Term_.def(constructor<const Expression&>());=0A=
=0A=
class_builder<Expression> Expression_(convert, "Expression");=0A=
Expression_.def(constructor<>());=0A=
=0A=
convert.def(f , "f");=0A=
=0A=
class_builder<A> A_(convert, "A");=0A=
A_.def(constructor<const Term&>());=0A=
}=0A=
catch(...)=0A=
{=0A=
} =0A=
}=0A=
=0A=
=0A=
=0A=
=0A=
------=_NextPart_000_0034_01C11E5E.E65E8DC0
Content-Type: application/octet-stream;
name="Makefile"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="Makefile"
# Revision History=0A=
=0A=
# 17 Apr 01 include cross-module support, compile getting_started1 =
(R.W. Grosse-Kunstleve)=0A=
# 17 Apr 01 build shared library (patch provided by Dan Nuffer)=0A=
# 04 Mar 01 Changed library name to libboost_python.a, various cleanups,=0A=
# attempted Cygwin compatibility. Still needs testing on Linux=0A=
# (David Abrahams)=0A=
=0A=
=0A=
LIBSRC =3D \=0A=
classes.cpp \=0A=
conversions.cpp \=0A=
cross_module.cpp \=0A=
extension_class.cpp \=0A=
functions.cpp \=0A=
init_function.cpp \=0A=
module_builder.cpp \=0A=
objects.cpp \=0A=
types.cpp=0A=
=0A=
LIBOBJ =3D $(LIBSRC:.cpp=3D.o)=0A=
OBJ =3D $(LIBOBJ)=0A=
=0A=
LIBNAME =3D libboost_python=0A=
# libpython2.1.dll=0A=
=0A=
ifeq "$(OS)" "Windows_NT"=0A=
ROOT=3D/=0A=
PYTHON_INC=3D/usr/local/include/python2.1=0A=
INC =3D -I/usr/include/g++-3 -I/usr/include -I/src/boost -I$(PYTHON_INC)=0A=
MODULE_EXTENSION=3Ddll=0A=
PYTHON_LIB=3D/usr/local/lib/python2.1/config/libpython2.1.dll.a=0A=
SHARED_LIB =3D $(LIBNAME).dll=0A=
CXXFLAGS +=3D -DUSE_DL_IMPORT=0A=
else=0A=
PYTHON_INC=3D$(ROOT)/usr/local/Python-2.1/include/python2.1=0A=
BOOST_INC=3D../../..=0A=
INC =3D -I$(BOOST_INC) -I$(PYTHON_INC)=0A=
MODULE_EXTENSION=3Dso=0A=
VERSION=3D1=0A=
SHARED_LIB =3D $(LIBNAME).so.$(VERSION)=0A=
endif=0A=
=0A=
%.o: ../src/%.cpp=0A=
g++ -fPIC -Wall -W $(INC) $(CXXFLAGS) -o $*.o -c $<=0A=
=0A=
%.d: ../src/%.cpp=0A=
@echo creating $@=0A=
@set -e; g++ -M $(INC) -c $< \=0A=
| sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \=0A=
[ -s $@ ] || rm -f $@=0A=
=0A=
=0A=
PYTHON =3D python=0A=
=0A=
all: test $(SHARED_LIB) getting_started1=0A=
=0A=
test: comprehensive.o $(LIBNAME).a $(SHARED_LIB)=0A=
g++ $(CXXFLAGS) -shared -o =
../test/boost_python_test.$(MODULE_EXTENSION) comprehensive.o -L. =
-lboost_python $(PYTHON_LIB)=0A=
$(PYTHON) ../test/comprehensive.py=0A=
=0A=
comprehensive.o: ../test/comprehensive.cpp=0A=
g++ $(CXXFLAGS) --template-depth-32 -fPIC -Wall -W $(INC) -o $*.o -c $<=0A=
=0A=
=0A=
getting_started1: getting_started1.o $(LIBNAME).a=0A=
g++ $(CXXFLAGS) -shared -o =
../example/getting_started1.$(MODULE_EXTENSION) getting_started1.o -L. =
-lboost_python $(PYTHON_LIB)=0A=
ln -s ../test/doctest.py ../example=0A=
$(PYTHON) ../example/test_getting_started1.py=0A=
=0A=
getting_started1.o: ../example/getting_started1.cpp=0A=
g++ $(CXXFLAGS) --template-depth-32 -fPIC -Wall -W $(INC) -o $*.o -c $<=0A=
=0A=
=0A=
clean:=0A=
rm -rf *.o *.$(MODULE_EXTENSION) *.a *.d *.pyc *.bak a.out=0A=
=0A=
$(LIBNAME).a: $(LIBOBJ)=0A=
rm -f $@=0A=
ar cqs $@ $(LIBOBJ)=0A=
=0A=
$(SHARED_LIB): $(LIBOBJ)=0A=
g++ $(CXXFLAGS) -shared -o $@ =
-Wl,--soname=3D$(LIBNAME).$(MODULE_EXTENSION)=0A=
=0A=
DEP =3D $(OBJ:.o=3D.d)=0A=
=0A=
ifneq "$(MAKECMDGOALS)" "clean"=0A=
include $(DEP)=0A=
endif=0A=
------=_NextPart_000_0034_01C11E5E.E65E8DC0
Content-Type: text/plain; charset=us-ascii
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
------=_NextPart_000_0034_01C11E5E.E65E8DC0--
- Raw text -