Detecting shared libraries on Windows with MinGW #602
Replies: 10 comments 24 replies
-
The best way to figure out what's going on is if we can somehow get access to meson-log.txt, although I think pip deleted everything on failure so that can be a bit confusing. Try passing Off the top of my head I think meson will automatically handle any libpath specified in link_args via a machine file or via $LDFLAGS. It's also possible to install pkg-config on Windows too, and let meson use that to detect gmp as a dependency instead of via find_library -- gmp.pc should be created because the autotools build on MinGW treats it as a kind of Unix and doesn't refuse to produce outputs it doesn't think are "interesting" on Windows (some projects have exactly this sort of manual logic via ifdefs for the msvc compiler). |
Beta Was this translation helpful? Give feedback.
-
Hello @oscarbenjamin. AFAICT, the issue you report does not have much to do with meson-python, but it is purely a Meson issue. meson-python is only the bridge between the Python build frontend and Meson, it is not involved in dependencies resolution. I'm saying this because none of the meson-python developers are very familiar with Windows, thus you may get better help on the Meson help channels. Indeed, when debugging this kind of issue, the first thing I recommend is to move cibuildwheel and meson-python out of the loop. Two less levels of indirection helps in getting to the cause of the problem faster. In the specific case, don't gmp, mpfr, and flint provide pkg-config files? To debug how Meson is trying to look up the dependencies, you need to look into the detailed Meson log file (pointed to in the last line of the console output you included). However, to get at it, you need to avoid pip deleting the temporary build directory. If you are stuck at the |
Beta Was this translation helpful? Give feedback.
-
Thanks all. I don't use Windows myself either and in fact I won't have access to a Windows machine for a few days at least so this is currently a debug via CI situation... Switching to pkg-config seems like the best idea and in keeping with how meson is supposed to work. I am testing with pkg-config now in flintlib/python-flint#129. Building wheels is working for OSX and Linux but failing on Windows with:
I guess there is something wrong with the MinGW environment that I just need to figure out or perhaps I am installing the wrong package... A new problem now though is that if I do $ PKG_CONFIG_PATH=$(pwd)/.local/lib/pkgconfig pip install .
Processing /Users/enojb/work/dev/python-flint
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: python-flint
Building wheel for python-flint (pyproject.toml) ... done
Created wheel for python-flint: filename=python_flint-0.6.0-cp312-cp312-macosx_14_0_arm64.whl size=1728563 sha256=65afc605ec9b90908b5bd2426887eabb052c83dc0a3f6c0abb5e3b44ec97140a
Stored in directory: /Users/enojb/Library/Caches/pip/wheels/dc/58/41/99d653384774c5a6090230bd9df1409f0209f328299de41900
Successfully built python-flint
Installing collected packages: python-flint
Successfully installed python-flint-0.6.0
$ DYLD_LIBRARY_PATH=$(pwd)/.local/lib python -m flint
Traceback (most recent call last):
File "<frozen runpy>", line 189, in _run_module_as_main
File "<frozen runpy>", line 148, in _get_module_details
File "<frozen runpy>", line 112, in _get_module_details
File "/Users/enojb/.pyenv/versions/python-flint-3.12.git/lib/python3.12/site-packages/flint/__init__.py", line 1, in <module>
from .pyflint import *
File "pyflint.pyx", line 1, in init flint.pyflint
File "flint_base.pyx", line 1, in init flint.flint_base.flint_base
ImportError: dlopen(/Users/enojb/.pyenv/versions/python-flint-3.12.git/lib/python3.12/site-packages/flint/flint_base/flint_context.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '_flint_cleanup' More strangely in CI the same operation seems to work or not depending on the version of Flint... Somehow I guess that using pkg-config and |
Beta Was this translation helpful? Give feedback.
-
Thanks. This has gotten me one step closer. Now the build fails with:
So it looks like the chocolatey pkg-config was found and meson is happy to use it. However it does not find gmp. This is all in CI for now so I added a few $ ls .local/lib
libgmp.dll.a
libgmp.la
pkgconfig
$ ls .local/bin
libgmp-10.dll
$ ls .local/lib/pkgconfig
gmp.pc
$ cat .local/lib/pkgconfig/gmp.pc
prefix=/d/a/python-flint/python-flint/.local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: GNU MP
Description: GNU Multiple Precision Arithmetic Library
URL: https://gmplib.org
Version: 6.3.0
Cflags: -I${includedir}
Libs: -L${libdir} -lgmp I have the environment variable The main difference I see for Windows is that the dll is in the I am not really sure how I can get the meson log out of CI. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure about this. All three libraries put the DLL files in $ ls .local/bin
libflint.19.0.0.dll
libflint.19.dll
libflint.dll
libgmp-10.dll
libmpfr-6.dll
$ ls .local/lib
libflint.dll.a
libgmp.dll.a
libgmp.la
libmpfr.dll.a
libmpfr.la
pkgconfig
$ ls .local/lib/pkginfo
flint.pc
gmp.pc
mpfr.pc It seems that the convention is that Note that I build these dependencies the same way when building with setuptools and building with setuptools works on Windows with MinGW as well as OSX and Linux. I am in any case testing what happens if I copy the DLL into lib. Just copying |
Beta Was this translation helpful? Give feedback.
-
This comment got hidden above so I am going to repeat it here because I think it is worth seeing:
|
Beta Was this translation helpful? Give feedback.
-
Okay, here is the log!: Click to expand
|
Beta Was this translation helpful? Give feedback.
-
It was working for OSX and Linux (before I butchered everything to try to get more info out of the Windows CI). Maybe it somehow doesn't work for Windows though because something else overrides it but only in the Windows case. I'll try setting the environment variable some other way.
I'm very much not a shell scripting expert but isn't that setting a local variable? Do you not need |
Beta Was this translation helpful? Give feedback.
-
I've followed the same and it looks like it's working! I have wheels built for Windows, Linux and OSX that seem to work. There is a problem with older Flint versions that I will investigate but otherwise all good! One mystery I have not yet resolved is what it is that is overriding the Thanks all for your help! |
Beta Was this translation helpful? Give feedback.
-
I don't think it is cibuildwheel or meson-python doing this but it could be meson: |
Beta Was this translation helpful? Give feedback.
-
Following on from #410 I am now attempting to convert python-flint's build system from setuptools to meson-python in flintlib/python-flint#129 (I am not attempting to do what was described in that discussion though). So far I have everything working to build wheels for OSX and Linux but the Windows build fails because meson-python cannot find the external shared library dependencies that we build beforehand.
The final part of the CI log is:
The way that this build works is that we first build GMP, MPFR and Flint which are all autotools-based. We install these into a build-local directory like:
./configure --prefix=$(pwd)/.local make make install
On Windows this is done with msys and MinGW.
Then we run cibuildwheel but set the environment variables
LIBRARY_PATH
etc to include the.local/lib
etc directories:https://github.com/flintlib/python-flint/blob/1ce152dffc356af69b1d4c2ea0eb08854f3d733b/pyproject.toml#L31-L35
With the current setuptools build this works on all operating systems and with Windows and MinGW in particular. With the meson-python configuration that I have so far this works on OSX and Linux but fails on Windows.
It looks like meson-python has correctly found the MinGW compiler but fails to find the
libgmp.dll
that we built. This is how the top-levelmeson.build
looks:One thing I know that differs between Windows and Unix is that .dlls are searched on
PATH
so I tried adding some directories to that as well but it did not help.Is there perhaps something that should be used instead of environment variables to make this work?
Should it be expected that
meson-python
would find these shared libraries in this situation (given that I think MinGW would be able to find them)?Another possibility in future is that we might use MSVC instead of MinGW for building the extension modules but we still need to use MinGW for the dependencies (for GMP in particular) so I assume that we will have the same problem somehow if using MSVC.
Beta Was this translation helpful? Give feedback.
All reactions