[Pyrex] Undefined symbol _Py_ZeroStruct

Franck Pommereau pommereau at univ-paris12.fr
Wed Sep 30 17:53:02 CEST 2009


Hi all,

I'm trying to use Pyrex/Cython to build a bridge between Python and Java
using JNI. It works on simple examples but fails on more complex ones.
Essentially, I have the following structure:

 - a file "hello.py" with a class "hello.Hello" inside
 - "_hello.pyx" that wraps the methods of "hello.Hello" to functions
    with the interface expected by JNI, it is compiled to "_hello.so"
 - "Hello.java" that defines a class to wrap "hello.Hello" through the
   functions provided in "_hello.so"

The trickery required to define "_hello.pyx" correctly is explained on
my blog:

http://pommereau.blogspot.com/2009/05/interfacing-java-and-python-through-jni.html

Everything is OK as long as module "hello" does not try to load and use
other modules. For instance, it could do

    import xml.dom.minidom
    xml.dom.minidom.parseString("...")

Then, function "init_hello" silently fails. I can notice it fails
because immediately after, the Python content of module "_hello" is not
available and "NameError"s are reported. If, just after calling
"init_hello", I manually try to import module "hello", this results in
an error report:

Exception ImportError: '/usr/lib/python2.6/lib-dynload/pyexpat.so:
undefined symbol: _Py_ZeroStruct' in '_hello.JNI_OnLoad' ignored

"_hello.JNI_OnLoad" is a function that calls "Py_Initialize()" and
"init_hello()" and that is called automatically by the JVM just after it
loaded "_hello.so". I tried to replace "xml.dom.minidom" with other
modules, this result in the same error (except that "pyexpat.so" is
replaced with what was required and loaded instead).

Notice that module "_hello" is always loaded perfectly from a Python
interpreter and I never get this undefined symbol problem.

I attach all the files required to reproduce the error.

Does anyone has an idea? I'd be very grateful for any hint, I'm out of
ideas...

Many thanks in advance,
Franck
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cythonjni.h
Type: text/x-chdr
Size: 182 bytes
Desc: not available
URL: <http://lists.copyleft.no/pipermail/pyrex/attachments/20090930/949416a5/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hello.py
Type: text/x-python
Size: 286 bytes
Desc: not available
URL: <http://lists.copyleft.no/pipermail/pyrex/attachments/20090930/949416a5/attachment.py>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: _hello.pyx
URL: <http://lists.copyleft.no/pipermail/pyrex/attachments/20090930/949416a5/attachment.ksh>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Hello.java
Type: text/x-java
Size: 587 bytes
Desc: not available
URL: <http://lists.copyleft.no/pipermail/pyrex/attachments/20090930/949416a5/attachment-0001.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Makefile
URL: <http://lists.copyleft.no/pipermail/pyrex/attachments/20090930/949416a5/attachment-0001.ksh>


More information about the Pyrex mailing list