[Python-Dev] Unable to build regex module against Python 3.5 32-bit

MRAB python at mrabarnett.plus.com
Fri Jun 5 03:28:51 CEST 2015


On 2015-06-05 01:37, MRAB wrote:
> On 2015-05-27 09:25, Paul Moore wrote:
>> On 27 May 2015 at 09:10, Nick Coghlan <ncoghlan at gmail.com> wrote:
>>> The old distutils docs aren't gone, the top level links just moved to the
>>> distutils package docs: https://docs.python.org/3/library/distutils.html
>>>
>>> I kept them (with the same deep link URLs) because I know there's stuff in
>>> there that isn't currently documented anywhere else. I moved them to a more
>>> obscure location because there's also stuff in there that's thoroughly
>>> outdated, and it's a non-trivial task to figure out which is which and move
>>> the still useful stuff to a more appropriate home :)
>>
>> Thanks.
>>
>> Your plan worked perfectly, because I never knew they were there :-)
>>
>> https://docs.python.org/3/install/index.html#older-versions-of-python-and-mingw
>> implies that the libpythonXY.a files are only needed in older versions
>> of Python/mingw. I don't know how true that is, although I do know
>> that mingw should be able to link directly to a DLL without needing a
>> lib file.
>>
>> It would be interesting to know if MRAB's build process can use the
>> DLL, rather than requiring a lib file (or for that matter if distutils
>> works without the lib file!)
>>
> Steve Dower's post has prompted me to look again at building the regex
> module for Python 3.5, 32-bit and 64-bit, using just Mingw64 and
> linking against python32.dll. It works!
>
> Earlier versions of Python, however, including Python 2.7, still seem
> to want libpython??.a.
>
For reference, here's how I can build the regex module on Windows 8.1,
64-bit, using only MinGW64.

For Python 3.5, I can link against "python35.dll", but for earlier
versions, including Python 2.7, I need "libpython.a".

I have built regex module for all of the 16 supported versions of
Python (2.5-2.7, 3.1-3.5, 64-bit and 32-bit) and they have all passed
the tests.


rem For Python 3.5, 64-bit.
rem Can link against the Python DLL.

rem Compile
"C:\MinGW64\bin\gcc.exe" -mdll -m64 -DMS_WIN64 -O2 -Wall -Wsign-compare 
-Wconversion -I"C:\Python35-64\include" -c 
"D:\mrab-regex\source\_regex_unicode.c" -o 
"D:\mrab-regex\release\3.5-64\_regex_unicode.o"

"C:\MinGW64\bin\gcc.exe" -mdll -m64 -DMS_WIN64 -O2 -Wall -Wsign-compare 
-Wconversion -I"C:\Python35-64\include" -c 
"D:\mrab-regex\source\_regex.c" -o "D:\mrab-regex\release\3.5-64\_regex.o"

rem Link
"C:\MinGW64\bin\gcc.exe" -m64 -shared -s 
"D:\mrab-regex\release\3.5-64\_regex_unicode.o" 
"D:\mrab-regex\release\3.5-64\_regex.o" -L"C:\Python35" -lpython35 -o 
"D:\mrab-regex\release\3.5-64\_regex.pyd"


rem For Python 3.5, 32-bit.
rem Can link against the Python DLL.

rem Compile
"C:\MinGW64\bin\gcc.exe" -mdll -m32  -O2 -Wall -Wsign-compare 
-Wconversion -I"C:\Python35-32\include" -c 
"D:\mrab-regex\source\_regex_unicode.c" -o 
"D:\mrab-regex\release\3.5-32\_regex_unicode.o"

"C:\MinGW64\bin\gcc.exe" -mdll -m32  -O2 -Wall -Wsign-compare 
-Wconversion -I"C:\Python35-32\include" -c 
"D:\mrab-regex\source\_regex.c" -o "D:\mrab-regex\release\3.5-32\_regex.o"

rem Link
"C:\MinGW64\bin\gcc.exe" -m32 -shared -s 
"D:\mrab-regex\release\3.5-32\_regex_unicode.o" 
"D:\mrab-regex\release\3.5-32\_regex.o" -L"C:\Python35-32" -lpython35 -o 
"D:\mrab-regex\release\3.5-32\_regex.pyd"


rem For Python 3.4, 64-bit.
rem Need to link against the Python .a file.

rem Make libpython34.a
"C:\MinGW64\x86_64-w64-mingw32\bin\gendef.exe" - 
"C:\Windows\System32\python34.dll" >"C:\Python34-64\libs\libpython34.def"

"C:\MinGW64\bin\dlltool.exe" --dllname python34.dll --def 
"C:\Python34-64\libs\libpython34.def" --output-lib 
"C:\Python34-64\libs\libpython34.a"

rem Compile
"C:\MinGW64\bin\gcc.exe" -mdll -m64 -DMS_WIN64 -O2 -Wall -Wsign-compare 
-Wconversion -I"C:\Python34-64\include" -c 
"D:\mrab-regex\source\_regex_unicode.c" -o 
"D:\mrab-regex\release\3.4-64\_regex_unicode.o"

rem Link
"C:\MinGW64\bin\gcc.exe" -mdll -m64 -DMS_WIN64 -O2 -Wall -Wsign-compare 
-Wconversion -I"C:\Python34-64\include" -c 
"D:\mrab-regex\source\_regex.c" -o "D:\mrab-regex\release\3.4-64\_regex.o"

"C:\MinGW64\bin\gcc.exe" -m64 -shared -s 
"D:\mrab-regex\release\3.4-64\_regex_unicode.o" 
"D:\mrab-regex\release\3.4-64\_regex.o" -L"C:\Python34-64\libs" 
-lpython34 -o "D:\mrab-regex\release\3.4-64\_regex.pyd"


rem For Python 3.4, 32-bit.
rem Need to link against the Python .a file.

rem Make libpython34.a
"C:\MinGW64\x86_64-w64-mingw32\bin\gendef.exe" - 
"C:\Windows\SysWOW64\python34.dll" >"C:\Python34-32\libs\libpython34.def"

"C:\MinGW64\x86_64-w64-mingw32\bin\dlltool.exe" --as-flags=--32 -m i386 
--dllname python34.dll --def "C:\Python34-32\libs\libpython34.def" 
--output-lib "C:\Python34-32\libs\libpython34.a"

rem Compile
"C:\MinGW64\bin\gcc.exe" -mdll -m32  -O2 -Wall -Wsign-compare 
-Wconversion -I"C:\Python34-32\include" -c 
"D:\mrab-regex\source\_regex_unicode.c" -o 
"D:\mrab-regex\release\3.4-32\_regex_unicode.o"

"C:\MinGW64\bin\gcc.exe" -mdll -m32  -O2 -Wall -Wsign-compare 
-Wconversion -I"C:\Python34-32\include" -c 
"D:\mrab-regex\source\_regex.c" -o "D:\mrab-regex\release\3.4-32\_regex.o"

rem Link
"C:\MinGW64\bin\gcc.exe" -m32 -shared -s 
"D:\mrab-regex\release\3.4-32\_regex_unicode.o" 
"D:\mrab-regex\release\3.4-32\_regex.o" -L"C:\Python34-32\libs" 
-lpython34 -o "D:\mrab-regex\release\3.4-32\_regex.pyd"


rem For earlier versions of Python, follow the pattern of Python 3.4.




More information about the Python-Dev mailing list