[英]How can I link python embedded in a c/c++ application
我想使用嵌入在 c++ 應用程序中的 python。 這是我的代碼:
#include <Python.h>
int
main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
return 0;
}
我已經包含在 c:\\log\\python27\\include 中以獲得 Python.h 和 c:\\log\\python27\\libs 以具有安裝在 c:\\log\\python27 中的相應的 python 鏈接庫它正在編譯但不是鏈接...為什么? 我總是有以下錯誤:
main.o:main.cpp:(.text+0x17): undefined reference to `_imp__Py_SetProgramName'
main.o:main.cpp:(.text+0x1e): undefined reference to `_imp__Py_Initialize'
main.o:main.cpp:(.text+0x34): undefined reference to `_imp__PyRun_SimpleStringFlags'
main.o:main.cpp:(.text+0x3b): undefined reference to `_imp__Py_Finalize'
如果你使用的是 python3.5,你可以使用這個簡單的命令
g++ test.cpp -I/usr/include/python3.5 -lpython3.5m -o call_function
取決於你的圖書館在哪里!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.