winlibs_mingw icon indicating copy to clipboard operation
winlibs_mingw copied to clipboard

Cython build failed during migration GCC 9.3.0 --> GCC 10.2.0

Open alkalinin opened this issue 5 years ago • 7 comments

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?

alkalinin avatar Sep 30 '20 10:09 alkalinin

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?

brechtsanders avatar Jan 26 '21 09:01 brechtsanders

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.

alkalinin avatar Apr 29 '21 10:04 alkalinin

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.

brechtsanders avatar Apr 29 '21 15:04 brechtsanders

Can you clarify what exactly you mean with "depends on libdl in Cython compilations"?

brechtsanders avatar Apr 29 '21 15:04 brechtsanders

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:

  1. Download and copy libdl package into the mingw64 folder.
  2. Add -ldl linking flag.

alkalinin avatar Apr 29 '21 16:04 alkalinin

It seems that Cython discourage you to use mingw-w64: https://github.com/cython/cython/wiki/CythonExtensionsOnWindows#less-useful-information

imba-tjd avatar May 15 '21 02:05 imba-tjd

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.

brechtsanders avatar May 15 '21 08:05 brechtsanders