c++ - 如何让 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====
解决方案
推荐阅读
- progressive-web-apps - Workbox - NetworkOnly 执行,即使我返回 false
- r - R - 根据单个列的多个条件从数据框中删除行
- julia - 为什么不考虑 cplex 中解决方案数量的限制?
- asp.net - ASP.NET Core - 如何压缩和调整图像大小和质量
- python - Rs deSolve 和 Pythons odeint 的区别
- javascript - JavaScript:显示是否有任何选项已赋值
- powerbi - 平均持续时间 DAX Power BI
- java - 引起:java.lang.IllegalArgumentException:transactionManager 是必需的
- c# - C#:如何在动态对象内部的数组中设置项的值?
- python - 处理像素坐标来自行列表的图像的像素值