SWIG和Mingw-64与Python一起使用...不是有效的 Win32 应用程序
SWIG and Mingw-64 to use with Python … not a valid Win32 application
我想使用Swig将我的C/C++"模型控制器"应用程序与Python HMI一起使用。
我首先在我的 ubuntu PC 上测试 python swig 简单示例,它就像一个魅力。
然后我尝试使用 Mingw-64 在 Win7-64 位上做同样的事情:
使用
swig.exe -python path_to_swig_examplespythonsimpleexample
在cmd窗口中,它会生成example_wrap.c...还行
然后在 mingw 终端下编译(我个人通过在资源管理器中右键单击然后在这里使用 Git Bash启动(
gcc -c -fPIC -DWIN32 example.c example_wrap.c -I/C/Program Files (x86)/Python36-32/include
生成我的对象...好的
和链接
ld -shared example.o example_wrap.o -o _example.dll
我有很多undefined reference
example_wrap.o:example_wrap.c:(.text+0xe3): undefined reference to `strlen'
example_wrap.o:example_wrap.c:(.text+0x1de): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0x5ff): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0x957): undefined reference to `strlen'
example_wrap.o:example_wrap.c:(.text+0x98f): undefined reference to `strcpy'
example_wrap.o:example_wrap.c:(.text+0x9c8): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0xa38): undefined reference to `strlen'
example_wrap.o:example_wrap.c:(.text+0xaaf): undefined reference to `strncpy'
example_wrap.o:example_wrap.c:(.text+0xaf5): undefined reference to `strcmp'
example_wrap.o:example_wrap.c:(.text+0xb11): undefined reference to `memset'
example_wrap.o:example_wrap.c:(.text+0xb57): undefined reference to `__imp_PyUnicode_AsUTF8String'
example_wrap.o:example_wrap.c:(.text+0xb76): undefined reference to `__imp_PyBytes_AsStringAndSize'
example_wrap.o:example_wrap.c:(.text+0xb88): undefined reference to `malloc'
example_wrap.o:example_wrap.c:(.text+0xbaa): undefined reference to `memcpy'
example_wrap.o:example_wrap.c:(.text+0xc15): undefined reference to `__imp_PyUnicode_FromString'
example_wrap.o:example_wrap.c:(.text+0xc69): undefined reference to `__imp_PyExc_MemoryError'
example_wrap.o:example_wrap.c:(.text+0xc7c): undefined reference to `__imp_PyExc_IOError'
example_wrap.o:example_wrap.c:(.text+0xc8f): undefined reference to `__imp_PyExc_RuntimeError'
example_wrap.o:example_wrap.c:(.text+0xca2): undefined reference to `__imp_PyExc_IndexError'
我添加了指向python36的链接.dll(基于Anaconda3:https://www.continuum.io/downloads(/c/ProgramData/Anaconda3/python36.dll
:
ld -shared example.o example_wrap.o/c/ProgramData/Anaconda3/python36.dll -o _example.dll
和 python undefined msg 消失了...但我仍然有 C/C++ 函数undefined reference
... 。
ld -shared example.o example_wrap.o/c/ProgramData/Anaconda3/python36.dll/c/Windows/System32/msvcr120.dll -o _example.dll
和dll被创建!
感谢您所有可用的 swig+python+mingw 编译信息都过时了吗?
。DLL 已创建,但不起作用:"ModuleNotFoundError: No module named '_example' "
没有名为_example的模块,
然后将 DLL 重命名为 PYD...ImportError: DLL load failed: %1 is not a valid Win32 application
......是因为它是我运行的 32 位的 python。
启动 anaconda python:
C:Program DataAnaconda3python.exe
Python 3.5.1 |Anaconda 4.4.0 (64-bit)…
>>> import example
>>> example.gcd(42,36)
6
>>> example.cvar.Foo
3.0
最后,它有效...经过很多时间!
版本:
视窗 7 sp1
斯威格 3.0.12
明W-64
蟒蛇3 4.4.0 gcc 6.2.0
/ld 2.25
- 试图在visual studio上用C++创建一个桌面应用程序
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 在C应用程序中运行C++(带有STL)函数
- SWIG和Mingw-64与Python一起使用...不是有效的 Win32 应用程序
- 程序'main.exe'运行失败:指定的可执行文件不是此操作系统平台的有效应用程序
- LoadLibrary失败带有错误4250:此操作仅在应用程序容器的上下文中有效
- 如何有效地构建QT应用程序
- 当从一个应用程序调用时,在DLL方法中创建COM接口指针是有效的,但当从另一个应用软件调用时则无效
- 创建 COM 接口指针在开发计算机上有效,但会导致其他计算机上的应用程序崩溃
- Exe不是有效的win32应用程序,但在64位上运行
- Visual Studio 2013 *.exe不是有效的Win32应用程序
- 由OpenCV 2.4.6创建的AVI文件在应用程序退出时并不总是有效
- 保存“编辑控件”用户输入并在应用程序重新启动C++Visual Studio时进行恢复的有效方法
- CMake:运行链接命令时出错:%1不是有效的Win32应用程序
- 使用 IPython 嵌入 Python 错误: [错误 193] %1 不是有效的 Win32 应用程序
- 实现 Web 应用程序的张量分解的最有效语言
- Qt5:阻止应用程序的另一个实例不再有效...!
- 开发c.未能执行.exe错误193:%1不是有效的win32应用程序
- 使用 VS2010 构建的可执行文件不是有效的 win32 应用程序;bindump 说它是一个 DLL
- 如何在Symbian应用程序中检查有效的联系人ID