Skip to content

Commit

Permalink
Make sure that finufftc links to libfinufft.so
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
janden committed Oct 7, 2020
1 parent f2232e2 commit ef2045f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?

Expand Down Expand Up @@ -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 <finufft.h>
void _dummy() {
nufft_opts opt;
finufft_default_opts(&opt);
}
""")


########## SETUP ###########
setup(
name='finufft',
Expand All @@ -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)

0 comments on commit ef2045f

Please sign in to comment.