dlltool失败,并显示python27.def文件

时间:2019-03-08 16:45:56

标签: python cross-compiling swig extension-modules

我想从python27.dll(C:Windows / SysWOW64)创建libpython27.a

我是Linux:

/usr/i686-w64-mingw32/bin/dlltool  -A --dllname python27.dll --def python27.def --output-lib libpython27.a
/usr/i686-w64-mingw32/bin/dlltool: Syntax error in def file python27.def:11

用-v运行dlltool,我得到:

/usr/i686-w64-mingw32/bin/dlltool: Using file: /usr/i686-w64-mingw32/bin/as
/usr/i686-w64-mingw32/bin/dlltool: Processing def file: python27.def
��/usr/i686-w64-mingw32/bin/dlltool: Syntax error in def file python27.def:11
/usr/i686-w64-mingw32/bin/dlltool: Processed def file
/usr/i686-w64-mingw32/bin/dlltool: Processing definitions
/usr/i686-w64-mingw32/bin/dlltool: Processed definitions
/usr/i686-w64-mingw32/bin/dlltool: Creating library file: libpython27.a
/usr/i686-w64-mingw32/bin/dlltool: run: /usr/i686-w64-mingw32/bin/as   -o dlumbh.o dlumbh.s
/usr/i686-w64-mingw32/bin/dlltool: run: /usr/i686-w64-mingw32/bin/as   -o dlumbt.o dlumbt.s
/usr/i686-w64-mingw32/bin/dlltool: Created lib file

如您所见,我收到了python27.def文件的语法错误,但libpython27.a已构建。

我按如下方式创建了python27.def :(在Windows中)

  • got pexports-0.47-mingw32-bin.tar.xz(支持32和64位)
  • 运行pexports.exe -v。\ python27.dll> python27.def

python27.def的内容:

; .text   : RVA: 00001000, File offset: 00000400
; .rdata  : RVA: 000e7000, File offset: 000e6000
; .data   : RVA: 001b9000, File offset: 001b7e00
; .rsrc   : RVA: 00214000, File offset: 00209200
; .reloc  : RVA: 00215000, File offset: 00209a00
; Reading exports from section: .rdata
; Export table: python27.dll
; Ordinal base: 1
; Ordinal table RVA: 001b3300
; Name table RVA: 01b22b4
; Export address table RVA: 001b1268
LIBRARY python27.dll
EXPORTS
PyAST_Compile ; .text ; RVA 000c1a03
PyAST_FromNode ; .text ; RVA 000b394f
PyArena_AddPyObject ; .text ; RVA 000d4279
PyArena_Free ; .text ; RVA 000d4211
PyArena_Malloc ; .text ; RVA 000d424f
PyArena_New ; .text ; RVA 000d41bd
PyArg_Parse ; .text ; RVA 000cb1d6
PyArg_ParseTuple ; .text ; RVA 000cb218
PyArg_ParseTupleAndKeywords ; .text ; RVA 000ccb89
PyArg_UnpackTuple ; .text ; RVA 000cd191
PyArg_VaParse ; .text ; RVA 000cb25a
PyArg_VaParseTupleAndKeywords ; .text ; RVA 000ccc5c
PyBaseObject_Type DATA ; .data ; RVA 001d4728
PyBaseString_Type DATA ; .data ; RVA 001d8058
PyBool_FromLong ; .text ; RVA 00065ad7
PyBool_Type DATA ; .data ; RVA 001e6470
PyBuffer_FillContiguousStrides ; .text ; RVA 000631b8
PyBuffer_FillInfo ; .text ; RVA 0006320a
PyBuffer_FromContiguous ; .text ; RVA 00062f13
PyBuffer_FromMemory ; .text ; RVA 00065e2a
PyBuffer_FromObject ; .text ; RVA 00065dac
...
...

创建python27.def的过程是否存在问题?

注意:下面有一个libpython27.a,但我读到一些注释,认为该链接无法在Linux中交叉编译python扩展模块。

谢谢!

1 个答案:

答案 0 :(得分:0)

最后,我从win-builds安装了gendef并创建了python27.def

.\gendef.exe C:\Windows\SysWOW64\python27.dll

然后,在Linux中,我成功运行dlltool来创建libpython27.a:

i686-w64-mingw32-dlltool -A --dllname python27.dll --def python27.def --output-lib libpython27.a

libpython27.a(gendef)的大小: 774580

libpython27.a的大小(失败于pexports):1470

win-builds