我试图用MingGw编译一个嵌入clio1.0.3中的python的简单示例。 来源主.cpp是:
#include <iostream>
#include "Python.h"
using namespace std;
int main() {
Py_Initialize();
PyRun_SimpleString("print('Hello World from Embedded Python!!!')");
Py_Finalize();
return 0;
}
我的CMakeList.txt文件文件是:
^{pr2}$但是当buils生成以下错误时:
Linking CXX executable pruebapy.exe
CMakeFiles\pruebapy.dir/objects.a(main.cpp.obj): In function `main':
C:/pruebapy/main.cpp:10: undefined reference to `_imp__Py_Initialize'
C:/pruebapy/main.cpp:12: undefined reference to `_imp__PyRun_SimpleStringFlags'
C:/pruebapy/main.cpp:14: undefined reference to `_imp__Py_Finalize'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\pruebapy.dir\build.make:87: recipe for target 'pruebapy.exe' failed
CMakeFiles\Makefile2:59: recipe for target 'CMakeFiles/pruebapy.dir/all' failed
makefile:74: recipe for target 'all' failed
mingw32-make.exe[2]: *** [pruebapy.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles/pruebapy.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
我尝试了不同的CMake配置,但错误仍然存在。我怎样才能解决这个问题?。在
而不是你的帮助。在
根据Python文档,“Python .h”的“包含”指令应该首先出现在C/C++文件中。在
注意,由于Python可能定义一些预处理器定义,这些定义会影响某些系统上的标准标头,因此在包含任何标准标头之前,必须先包含Python.h https://docs.python.org/2/extending/extending.html
先试试这个。在
如果出现长位错误,这可能是由于Python和CygWWin或MinGw的编译器不匹配造成的。从大多数python(all?)开始,尝试使用支持msvisualstudio编译器的Clion早期访问版本是用那个编译器编译的。在
相关问题 更多 >
编程相关推荐