Clion错误使python嵌入

Clion错误使python嵌入,python,c++,clion,Python,C++,Clion,我尝试用MingGw编译一个嵌入到clio1.0.3中的简单python示例。 源main.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; } 但当

我尝试用MingGw编译一个嵌入到clio1.0.3中的简单python示例。 源main.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;
}
但当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文档,C/C++文件中应该首先出现“Python.h”的include指令

注意:由于Python可能会定义一些影响某些系统上的标准头的预处理器定义,因此在包含任何标准头之前,必须包含Python.h

先试试这个


如果出现长位错误,似乎是由于Python和CygWWin或MinGw的编译器不匹配。尝试使用MS Visual Studio编译器支持的早期Access版本的Clion,因为大多数Python(all?)都是使用该编译器编译的。

您好,我可以解决冲突。我发现在gnu for windows的安装中存在两个gcc版本3.4和4.9。然后,当链接器访问对象文件时,链接器采用版本3.4,但源代码是用4.9编译的。我使用Uninstall 3.4并解决问题。非常感谢。
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