首页 > 解决方案 > 如何让 python.h 与 mingw gcc 编译器一起工作

问题描述

我已经包含了 python.h(C:\Users\vinay\AppData\Local\Programs\Python\Python37-32\include) 文件的路径,并将项目的库路径提供给“C:\Users\AppData\Local \Programs\Python\Python37-32\Lib",我的代码粘贴如下:-

    #include <iostream>
    #include <Python.h>
    using namespace std;

    int main(int argc, char **argv)
    {
        PyObject *pInt;
        Py_Initialize();
        PyRun_SimpleString("print('Hello world from embedded python!!!\n')");
        Py_Finalize();
        cout<<"now i am finally out of the python"<<endl;
        return 0;

    }

当我编译程序时没有错误,但是当我构建项目时,我得到以下错误

C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:8: undefined reference to `_imp__Py_Initialize'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:9: undefined reference to `_imp__PyRun_SimpleStringFlags'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:/Users/Documents/CppWorkspace/Cpp_in_python/main.cpp:10: undefined reference to `_imp__Py_Finalize'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/Cpp_in_python] Error 1
mingw32-make.exe: *** [All] Error 2
Cpp_in_python.mk:78: recipe for target 'Debug/Cpp_in_python' failed
mingw32-make.exe[1]: Leaving directory 'C:/Users/vinay/Documents/CppWorkspace/Cpp_in_python'
Makefile:4: recipe for target 'All' failed
====4 errors, 0 warnings====

标签: c++python-3.xgccmingwcodelite

解决方案


推荐阅读