omnet++ 中c++调用python的常见错误和解决

我是用的32位mingw,32位python3.7。

1、错误和解决:

错误1:undefined reference to '_imp__Py_Initialize':

原因:没有使用32位的python37.lib或没有在编译时引用python37.lib,如果mingw是32位,python就用32位。

错误2:ld.exe: cannot find -lpython37.lib:

原因:没有正确引用python37.lib或者没有python37.lib这个文件,应该直接使用-lpython37,不要.lib。

解决错误1和2:

1、使用32位的python。
2、在项目中加上引用、连接上所需的文件(详看下面第二节)。编译时加上命令:-LC:/Python37-32/libs/(plthon37.lib所在路径),-lpython37(python37.lib)

错误3:应用程序无法正常启动0xc000007b

原因:没有使用32位的python,(也可能环境变量中32位的被前面的覆盖了)

错误4:找不到libgcc_s_dw2-1.dll:

原因:mingw32/bin目录下没有这个库。

解决错误3和4:

1、环境变量一定是32位的mingw下的mingw32下的bin,检查有没有被覆盖,我就是这样被坑了好久。(如:C:\MinGW\mingw32\bin\)
2、其次将MinGW\bin\中的libgcc_s_dw2-1.dll文件复制到MinGW\mingw32\bin\中。粗暴但是好用

错误5:Permission denied:

原因:程序正在运行,在任务管理器中把运行的.exe程序关掉就好。

2、总结:

1、下载pyDev:

Help->Install New Software->Add,Name:PyDev,Location:http://pydev.org/updates,选中PyDev下载。如果上面这个网址不好使可以换成这个试试看:https://dl.bintray.com/fabioz/pydev/old/

omnet++ 中c++调用python的常见错误和解决

omnet++ 中c++调用python的常见错误和解决 

2、配置python解释器:

 Window->Preferences->PyDev->Interpreters->Python Interpreter右边Browse for python选中python目录下的python.exe,应用。

 omnet++ 中c++调用python的常见错误和解决

3、右键项目->Properties->C/C++ General->paths and symbols,在右边Includes中加入\Python37-32\include和\Python37-32\libs,在Libraries中加入python37,在library Paths中加入\Python37-32\libs,应用:

omnet++ 中c++调用python的常见错误和解决

 

 omnet++ 中c++调用python的常见错误和解决

 omnet++ 中c++调用python的常见错误和解决

 4、bulid and run