Author damahay123
Recipients damahay123
Date 2009-08-20.13:32:00
SpamBayes Score 8.04091e-11
Marked as misclassified No
Message-id <>
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 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 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;
    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");

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;

    return 0;

here is my makefile

CXX := g++

default: DLOpenTest

DLOpenTest: DLOpen.C
	$(CXX) -o DLOpenTest DLOpen.C -ldl
-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.C
	$(CXX) -shared -nostartfiles
-L/mnts/cdstools/Python-2.6.2/aix-ppc-5.3/lib/ -lpython2.6 -lpthread -o mypython.C

	rm *.o DLOpenTest

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
Date User Action Args
2009-08-20 13:32:02damahay123setrecipients: + damahay123
2009-08-20 13:32:02damahay123setmessageid: <>
2009-08-20 13:32:01damahay123linkissue6742 messages
2009-08-20 13:32:00damahay123create