【发布时间】:2017-12-21 21:04:39
【问题描述】:
试图将 python 解释器嵌入到 c++ 应用程序中。认为这将是直截了当的,但我在链接方面遇到了麻烦。唯一不寻常的是我正在尝试使用特定的 Anaconda 包。简单的c++代码是:
# include <Python.h>
int main()
{
printf("before initialize");
Py_Initialize();
printf("after initialize");
PyRun_SimpleString("print('Hello from Python')");
Py_Finalize();
return 0;
}
编译我使用:
gcc pythonTest.cc -I/path/to/anaconda/include/python3.6m -L/path/to/anaconda/lib/python3.6/config-3.6m-x86_64-linux-gnu -lm -lpthread -ldl -lutil -lpython3.6m -o pytest
它确实可以编译,但是当我运行这个简单的程序时,我得到了:
Fatal Python error: PyThreadState_Get: no current thread
before initializeAborted
我检查了程序看到的路径,它确实包含了与我使用包含和库指定的相同 python 可执行文件的路径。但是,一些搜索似乎表明调用的 python 版本与链接的版本有所不同。我有点不知如何解决这个问题。
【问题讨论】:
-
我也有同样的问题。你有没有设法解决这个问题?
标签: python c++ anaconda linker-errors embedding