Re: Undefined symbol _Py_ZeroStruct
Franck Pommereau <[email protected]> Thu, 01 Oct 2009 09:43:45 +0200
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
> You are probably right...it looks like a linking problem rather than > directly a Pyrex issue. One thing I might look at is the (long) lost of > command line options used by gcc when useing distutils, and making sure > none of them are missing when you try to compile for use from Java. Thanks for the idea! It does change something but still there is a missing symbol. I copied/pasted distutils flags and just added the required -I directives for JNI: $ gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/lib/jvm/java-6-sun-1.6.0.10/include -I/usr/lib/jvm/java-6-sun-1.6.0.10/include/linux -I/usr/include/python2.6 -c _sr.c -o _sr.o $ gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions _sr.o -o _sr.so The error at the Python side seems to be the same, but the Java program is happier and successfully loads the built library. I used to have: $ java Tester Exception ImportError: '/usr/lib/python2.6/lib-dynload/pyexpat.so: undefined symbol: _Py_ZeroStruct' in '_sr.JNI_OnLoad' ignored Exception in thread "main" java.lang.UnsatisfiedLinkError: unsupported JNI version 0x4063F2C0 required by /home/franck/work/tools/snakes/osa/trivial/_sr.so at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1778) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1674) at java.lang.Runtime.load0(Runtime.java:770) at java.lang.System.load(System.java:1003) at Component.<clinit>(Component.java:3) at Tester.main(Tester.java:3) where the first exception is reported by Cython's runtime. I now have: $ java Tester Exception ImportError: '/usr/lib/python2.6/lib-dynload/pyexpat.so: undefined symbol: _Py_ZeroStruct' in '_sr.JNI_OnLoad' ignored *** Yeah! Exception NameError: 'sr' in '_sr.Java_Sender_pynew' ignored Exception NameError: '_instances' in '_sr.Java_Sender_pyinit' ignored Exception in thread "main" java.lang.NullPointerException at java.lang.String.valueOf(String.java:2826) at java.lang.StringBuilder.append(StringBuilder.java:115) at Tester.main(Tester.java:4) where message "*** Yeah!" is printed by the Java program after it has loaded the library. The subsequent NameError's come from the fact that my Python module is not correctly initialized because function init_sr called from _sr.JNI_OnLoad failed. I presume that this change is just a random one, probably the value returned by JNI_OnLoad is now acceptable by the JVM that thus continues the execution. F.