From ef2045f316d497afed7a1fc4275442667affeed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20And=C3=A9n?= Date: Wed, 7 Oct 2020 10:56:38 +0200 Subject: [PATCH] Make sure that finufftc links to libfinufft.so On certain systems, the default ld option --no-as-needed is overridden by --as-needed, which means that only dynamic libraries which contain symbols that unresolved in the main object files are included in the DT_NEEDED fields. This happens, for example, on Ubuntu 20.04. To resolve this, we create a temporary source file which contains a call to a function in `libfinufft.so`, forcing the linker to include it. --- python/setup.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/python/setup.py b/python/setup.py index 3ae0e1429..935b41241 100644 --- a/python/setup.py +++ b/python/setup.py @@ -17,6 +17,8 @@ import os import ctypes +from tempfile import mkstemp + # libin to change to python-dotenv or whatever's simplest: import dotenv # is this part of standard python? (install_requires fails) ? @@ -51,6 +53,29 @@ finufft_dlib = finufftdir+"/lib/finufft" finufft_lib = finufftdir+"/lib-static/finufft" +# For certain platforms (e.g. Ubuntu 20.04), we need to create a dummy source +# that calls one of the functions in the FINUFFT dynamic library. The reason +# is that these platforms override the default --no-as-needed flag for ld, +# which means that the linker will only link to those dynamic libraries for +# which there are unresolved symbols in the object files. Since we do not have +# a real source, the result is that no dynamic libraries are linked. To +# prevent this, we create a dummy source so that the library will link as +# expected. +fd, source_filename = mkstemp(suffix='.c', text=True) + +with open(fd, 'w') as f: + f.write( \ +""" +#include + +void _dummy() { + nufft_opts opt; + + finufft_default_opts(&opt); +} +""") + + ########## SETUP ########### setup( name='finufft', @@ -67,8 +92,10 @@ py_modules=['finufft/finufftc'], ext_modules=[ Extension(name='finufft/finufftc', - sources=[], + sources=[source_filename], + include_dirs=[inc_dir], libraries=[finufft_dlib]) ] ) +os.unlink(source_filename)