在64位操作系统上构建C-> Python库

时间:2012-02-14 16:53:20

标签: python visual-studio 64-bit swig 32-bit

我有一个第三方库,我用Swig包装,以便我可以用Python与它交谈。这适用于32位OS / Python /第三方库。最近我从第三方收到了这些库的64位版本,所以我想重建这些库以利用它(当然使用64位Python和64位操作系统)。但是,当我尝试导入库时,我收到此错误:

Traceback (most recent call last):
  File "camera.py", line 1, in <module>
    import memhandler
  File "C:\neo\memhandler.py", line 26, in <module>
    _memhandler = swig_import_helper()
  File "C:\neo\memhandler.py", line 22, in swig_import_helper
    _mod = imp.load_module('_memhandler', fp, pathname, description)
ImportError: DLL load failed: %1 is not a valid Win32 application.

(memhandler是我正在构建的SWIG库之一) 由于32位/ 64位不匹配,我的搜索已经出现了其他出现此错误的人,因此这似乎表明某种架构不匹配,但我无法弄清楚它出错的地方。

我正在使用Visual Studio 2008的命令行来链接Python 2.7 64位;那里没有版本不匹配(换句话说,Python 2.7 64位是使用相同的编译器构建的)。我过去用不同的程序成功完成了这项工作;遗憾的是,我不能通过比较这个与这个有什么不同来判断。我正在使用64位编译器(通过在启动之前运行“vcvarsall.bat amd64”)。

这是我的Makefile:

PYROOT = C:\Python27x64
PYINCLUDE = /I$(PYROOT)\include /I$(PYROOT)\Lib\site-packages\numpy\core\include
PYLIBS = /LIBPATH:$(PYROOT)\libs python27.lib
ANDORLIBS = "Andor SDK3\atcorem.lib"
LIBS = $(PYLIBS) $(ANDORLIBS)

CXXFLAGS = /MD /EHsc /DWIN32 /D_WINDOWS /DNOPCH /O2 $(PYINCLUDE)

# We have two separate SWIG libraries to build here; one calls most of the
# Andor functions; the other does some intermediary work for us before
# calling certain special Andor functions. We also have to compile the
# intermediary library ourselves.
ANDOROBJS = neo_wrap.obj
WRAPOBJS = memhandler.obj
WRAPSWIGOBJS = memhandler_wrap.obj

ANDORTARGET = _neo.pyd
WRAPTARGET = _memhandler.pyd

all: $(ANDORTARGET) $(WRAPTARGET)

$(ANDORTARGET): $(ANDOROBJS)
    link /dll /DEBUG /NOLOGO /out:$@ /SUBSYSTEM:WINDOWS $(ANDOROBJS) $(LIBS)

$(WRAPTARGET): $(WRAPOBJS) $(WRAPSWIGOBJS)
    link /dll /DEBUG /NOLOGO /out:$@ /SUBSYSTEM:WINDOWS $(WRAPOBJS) $(LIBS)
    link /dll /DEBUG /NOLOGO /out:$@ /SUBSYSTEM:WINDOWS $(WRAPSWIGOBJS) $(LIBS) memhandler.obj

swig:
    C:\swigwin-2.0.4\swig.exe -c++ -python neo.i
    C:\swigwin-2.0.4\swig.exe -c++ -python memhandler.i

clean:
    del *ilk *lib *pdb *obj *exp *wrap.cxx *pyd *pyd.manifest

有什么想法吗?关于我唯一能想到的是我实际上没有64位库;我不知道如何判断DLL / LIB文件是64位还是32位。

0 个答案:

没有答案
相关问题