开发者

Importing ctype; embedding python in C++ application

I'm trying to embed python within a C++ based programming language (CCL: The compuatational control language, not that any of you have heard of it). Thus, I don't really have a "main" function to make calls from.

I have made a test .cc program with a main, and when I compile it and run it, I am able to import my own python modules and system modules for use.

When I embed my code in my CCL-based program and compile it (with g++), it seems I have most functionality, but I get a RUNTIME error: ImportError: /usr/lib/python2.6/lib-dynload/_ctypes.so: undefined symbol: PyType_GenericNew

This is the code that is executed at Runtime error.

void FFSim::initCKBot (){   
    Py_Initialize(); 
    PyRun_SimpleString("execfile('logical.py')");
}
开发者_StackOverflow

logical.py imports modules, one of which attempts to execute 'from cytpes import *', which throws the runtime error.

Can someone explain this to me and how to go about solving it? It seems like I've linked the objects correctly when compiling the c++ aspect of the code.

Thanks.


The Python runtime is effectively a collection of libraries that your program uses. Those libraries take strings, convert them to Python bytecode and then interpret the bytecode. The error you're getting is that as part of interpreting the program, the Python runtime needs to call a function (PyType_GenericNew), but that function does not exist in the compiled Python runtime on your system. Going off the name of the function, this isn't something you can ignore or workaround. It's a fundamental part of the runtime.

Assuming your PATH is correct, your best solution is to reinstall or rebuild Python. Your installation is missing something important.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜