Cython build failed during migration GCC 9.3.0 --> GCC 10.2.0
I use this wonderful MingGW package in my Cython projects to build C extensions. But during the migration from GCC 9.3.0 to the GCC 10.2.0 I get the problem during the static build.
See details in https://github.com/cython/cython/issues/3851
In GCC 9.3.0 we have the following dependencies:
- libgcc_s_seh-1.dll
- libgomp-1.dll
- libwinpthread-1.dll
In GCC 10.20 we have one more dependence:
- libgcc_s_seh-1.dll
- libgomp-1.dll
- libwinpthread-1.dll
- libdl.dll
However there is no libdl.a in the mingw folder. Is it possible to include "libdl.a" into the mingw build?
For the new release https://github.com/brechtsanders/winlibs_mingw/releases/tag/10.2.0-11.0.0-8.0.0-r6 I have tried to minimize dependancies on libdl, but I'm afraid gcc.exe itself still depends on it. Can you check if this release works better for you?
I checked the latest release "GCC 10.3.0 + LLVM/Clang 11.1.0 + MinGW-w64 8.0.0 (release 2)" and this release also depends on libdl in Cython compilations.
However I added manually the libdl library into the distributive and everything works good in my environment.
libdl.dll is present in that distribution If any software that you build has it's own libdl dependancy then you should indeed build libdl (from https://github.com/dlfcn-win32/dlfcn-win32) and have it available to build your source.
Can you clarify what exactly you mean with "depends on libdl in Cython compilations"?
I am a Python developer. Cython is the special language and the special tool for writing binary extension for the Python.
The Cython workflow is following: .pyx python extension source file --> .pyx to .c cython conversion --> compiling .c to the binary. For the last step we need C compiler. I use the gcc.
The compilation string looks like
gcc -mdll -O -Wall -IC:\Dev\Python\python-3.9\lib\site-packages\numpy\core\include -IC:\Dev\Python\python-3.9\include -IC:\Dev\Python\python-3.9\include -c src-py/nuance/algs\linalg_ext.c -o build\temp.win-amd64-3.9\Release\src-py\nuance\algs\linalg_ext.o -O3 -fopenmp -fvisibility=hidden -flto -fno-fat-lto-objects -DMS_WIN64
gcc -shared -s build\temp.win-amd64-3.9\Release\src-py\nuance\algs\linalg_ext.o build\temp.win-amd64-3.9\Release\src-py\nuance\algs\linalg_ext.cp39-win_amd64.def -LC:\Dev\Python\python-3.9\libs -LC:\Dev\Python\python-3.9\PCbuild\amd64 -lpython39 -o C:\WST-Stage\nuance\src-py\nuance\algs\linalg_ext.cp39-win_amd64.pyd -fopenmp -static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive
and errors look like
c:/dev/mingw/x86_64-10.3.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/dev/mingw/x86_64-10.3.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../lib\libgomp.a(target.o):(.text+0x39f): undefined reference to `dlopen'
c:/dev/mingw/x86_64-10.3.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/dev/mingw/x86_64-10.3.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../lib\libgomp.a(target.o):(.text+0x3ba): undefined reference to `dlsym'
c:/dev/mingw/x86_64-10.3.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/dev/mingw/x86_64-10.3.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.3.0/../../../../lib\libgomp.a(target.o):(.text+0x3ef): undefined reference to `dlclose'
Here I use the -static-libgcc flag because I need the static assembling, the reason is the Python 3.8+ rule of the dll resolution process.
My solution is:
- Download and copy libdl package into the mingw64 folder.
- Add
-ldllinking flag.
It seems that Cython discourage you to use mingw-w64: https://github.com/cython/cython/wiki/CythonExtensionsOnWindows#less-useful-information
I understand why they are saying that, as mixing runtimes should be avoided at all cost. I would like to be able to build Python or CPython and all of the dependancies with MinGW-w64. Then there would be no mix of runtimes. Unfortunately I'm stuck at building Python with MinGW-w64: static build works, but shared build still won't link.