简体   繁体   English

C++ - 如何链接 python 库?

[英]C++ - How link python library?

Im trying to link python for execute this code:我试图链接 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;
}

But I got this error:但我得到了这个错误:

||=== 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'|
(....)

I linked 'python\include' and 'python\libs', anyone how what I can do?我链接了 'python\include' 和 'python\libs',任何人都可以怎么做? Im using Codeblocks and MinGW.我正在使用代码块和 MinGW。

You need to build with Python headers:您需要使用 Python 标头进行构建:

g++ main.cpp `python3-config --includes` -o main

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM