[C++-sig] boost.python and MinGW

David Abrahams dave at boost-consulting.com
Fri Apr 11 10:57:52 CEST 2003


Andreas Beyer <beyer at imb-jena.de> writes:

> Hi,
>
> I am trying to compile and use boost.python with MinGW.
> Although compiling works, I get strange errors when using it. The
> hello world' example from the boost.python tutorial works
> fine. However, as soon as I try to access a class attribute python
> crashes without raising an exception (which makes it difficult for me
> to debug the error).

Weird.  Works fine for me.

> If I compile boost.python with MSVC it works fine.
>
> For compiling boost.python with MinGW I have taken the following steps:
> 1. Create python22.def with pexports v. 0.43
>     (Python 2.2.2)
> 2. Create libpython22.a with dlltool v. 2.13
> 3. Run 'bjam -sTOOLS=mingw' in python\test,
>     (boost 1.30.0, bjam 3.1.4)
> 4. Create libboost_python.a as above
> 5. Compile the example from below with Python's distutil (I was too
>      lazy to create a jam-file)

I'm too lazy to figure out how to get distutils to work reliably for C++.
Creating a Jamfile is simple as pie.  Please try that instead.

> This is my example:
>
> #include <boost/python.hpp>
> using namespace boost::python;
>
> char const * greet() {
> 	return "hello world!";
> }
>
> struct World
> {
> 	int hallo;
> };
>
> BOOST_PYTHON_MODULE(hello) {
> 	def("greet", greet);
> 	class_<World>("World")
> 		.def_readwrite("hallo", &World::hallo);
> }
>
> This is the compiler call for the example (no warnings):
> C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\boost_1_30_0
> -IC:\Python22\include -c hello.cpp -o
> build\temp.win32-2.2\Release\hello.o
> C:\MinGW\bin\dllwrap.exe -mno-cygwin -mdll -static --entry _DllMain at 12
> --output-lib build\temp.win32
> -2.2\Release\libhello.a --def build\temp.win32-2.2\Release\hello.def
>    -s
> build\temp.win32-2.2\Release
> \hello.o -LC:\Python22\libs -lstdc++ -lboost_python -lpython22 -o
> build\lib.win32-2.2\hello.pyd
>
>
> I cannot access the attribute 'hallo', although greet() works fine.
> The following python session crashes in the last line without warning:
>  >>import hello
>  >>hello.greet()
> 'hello world!'
>  >>ob=hello.World()
>  >>ob.hallo
>
> Any ideas?

Well, you're reading unininitialized data, which is undefined
behavior.  I don't think it should crash MinGW, though.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list