[英]C++ - How link python library?
我試圖鏈接 python 以執行此代碼:
#include <Python.h>
int main(int argc, char *argv[])
{
Py_SetProgramName((wchar_t *)argv[0]); /* optional but recommended */
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print('Today is', ctime(time()))\n");
Py_Finalize();
return 0;
}
但我得到了這個錯誤:
||=== Build: Debug in test (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
C:\Users\xxxxxxxxxxxxxxxxxxxxxx\test\test\main.cpp|5|undefined reference to `__imp_Py_SetProgramName'|
(....)
我鏈接了 'python\include' 和 'python\libs',任何人都可以怎么做? 我正在使用代碼塊和 MinGW。
您需要使用 Python 標頭進行構建:
g++ main.cpp `python3-config --includes` -o main
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.