New submission from damahay123 <hong....@algorithmics.com>: Hi there, I'm trying to embedding my python code into a .so on AIX and load it with my main application. Since there is no libpython2.6.so available on AIX, I have to link my .so with libpython2.6.a. I have to make some twist to make it compile. And so far so good until I run my main. My embedding python .so give me error like the following Fatal Python error: Interpreter not initialized (version mismatch?) I check the initialization status by calling Py_IsInitialized and it said yes. So I'm wondering if this embedding python into .so ever work on AIX. I have no problem to do the same thing on linux, solaris since python has libpython2.6.so on both system. But our system needs the supoort on AIX. My embedding python is very simple like the following
#include <Python.h> #include <iostream> extern "C" void allocate() { std::cout << " am i ok = " << Py_IsInitialized() << std::endl; Py_InitializeEx(0); std::cout << " am i ok 1 = " << Py_IsInitialized() << std::endl; PyRun_SimpleString("from time import time, datetime, ctime\n" "print 'Today is',ctime(time())\n"); Py_Finalize(); } my main application is also very simple #include <iostream> #include <iomanip> #include <dlfcn.h> //#include <link.h> #include <Python.h> typedef void (*ALLOCATE)(); int main (int argc, char ** argv) { // parse params to load shared object if (argc < 2) { std::cerr << "Usage: " << argv[0] << " sharedObject(s)" << std::endl; return 0; } // Py_Initialize(); for (int i = 1; i < argc; ++i) { void * handle = ::dlopen(argv[i], RTLD_LAZY); if (!handle) { std::cerr << dlerror() << argv[i] << std::endl; return 0; } // Use that handle to locate the symbol. The symbol must be // demangled so it has to be compiled with extern "C". ALLOCATE dlmAllocate = (ALLOCATE) ::dlsym(handle, "allocate"); if (!dlmAllocate) { std::cerr << dlerror() << std::endl; return 0; } dlmAllocate(); } return 0; } here is my makefile CXX := g++ default: DLOpenTest mypython.so DLOpenTest: DLOpen.C $(CXX) -o DLOpenTest DLOpen.C -ldl -Wl,-bE:/mnts/cdstools/Python-2.6.2/aix-ppc-5.3/lib/python2.6/config/python.exp -lld -I/mnts/cdstools/Python-2.6.2/aix-ppc-5.3/include/python2.6 -L/mnts/cdstools/Python-2.6.2/aix-ppc-5.3/lib/ -lpython2.6 -lpthread mypython.so: mypython.C $(CXX) -shared -nostartfiles -I/mnts/cdstools/Python-2.6.2/aix-ppc-5.3/include/python2.6 -L/mnts/cdstools/Python-2.6.2/aix-ppc-5.3/lib/ -lpython2.6 -lpthread -o mypython.so mypython.C clean: rm *.o DLOpenTest mypython.so Can someone help me out? Or has anyone even tried same thing on AIX? NOTE, the issue is not like issue 4434 or 1332869. Please don't reply this issue with those two number. I've seen them already. It's not helpful Thanks a log ---------- components: Interpreter Core messages: 91773 nosy: damahay123 severity: normal status: open title: Embedding python into shared library crash on AIX type: crash versions: Python 2.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6742> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com