sleef
sleef copied to clipboard
Build issue: undefined reference to `clock_gettime'
I'm encountering the following build issue on my system:
[99/308] /mnt/a/u/sciteam/stewart1/spack/lib/spack/env/gcc/gcc -DENABLE_ALIAS=1 -DUSEMPFR=1 -I/scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-src/src/common -I/scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-src/src/arch -Iinclude -I/scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-src/src/libm -Isrc/libm/include -Wall -Wno-unused-function -Wno-attributes -Wno-unused-result -Wno-psabi -ffp-contract=off -fno-math-errno -fno-trapping-math -fno-strict-aliasing -O3 -DNDEBUG -std=gnu99 -MD -MT src/libm-tester/CMakeFiles/tester2dp.dir/testerutil.c.o -MF src/libm-tester/CMakeFiles/tester2dp.dir/testerutil.c.o.d -o src/libm-tester/CMakeFiles/tester2dp.dir/testerutil.c.o -c /scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-src/src/libm-tester/testerutil.c
[100/308] : && /mnt/a/u/sciteam/stewart1/spack/lib/spack/env/gcc/gcc -Wall -Wno-unused-function -Wno-attributes -Wno-unused-result -Wno-psabi -ffp-contract=off -fno-math-errno -fno-trapping-math -fno-strict-aliasing -O3 -DNDEBUG src/libm-tester/CMakeFiles/tester2dp.dir/tester2dp.c.o src/libm-tester/CMakeFiles/tester2dp.dir/testerutil.c.o -o bin/tester2dp -L/mnt/c/scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-build-2qysp4q/lib -L/mnt/c/scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-build-2qysp4q/src/common -Wl,-rpath,/mnt/c/scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-build-2qysp4q/lib:/mnt/c/scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-build-2qysp4q/src/common lib/libsleef.so.3.6.0 /usr/lib64/libmpfr.so /usr/lib64/libm.so /usr/lib64/libgmp.so && :
FAILED: bin/tester2dp
: && /mnt/a/u/sciteam/stewart1/spack/lib/spack/env/gcc/gcc -Wall -Wno-unused-function -Wno-attributes -Wno-unused-result -Wno-psabi -ffp-contract=off -fno-math-errno -fno-trapping-math -fno-strict-aliasing -O3 -DNDEBUG src/libm-tester/CMakeFiles/tester2dp.dir/tester2dp.c.o src/libm-tester/CMakeFiles/tester2dp.dir/testerutil.c.o -o bin/tester2dp -L/mnt/c/scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-build-2qysp4q/lib -L/mnt/c/scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-build-2qysp4q/src/common -Wl,-rpath,/mnt/c/scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-build-2qysp4q/lib:/mnt/c/scratch/sciteam/stewart1/spack-stage-sleef-master-2qysp4qup7zd4pa2u4fa26e73rwpj6v6/spack-build-2qysp4q/src/common lib/libsleef.so.3.6.0 /usr/lib64/libmpfr.so /usr/lib64/libm.so /usr/lib64/libgmp.so && :
src/libm-tester/CMakeFiles/tester2dp.dir/tester2dp.c.o: In function `main':
tester2dp.c:(.text.startup+0x1f55): undefined reference to `mpfr_fmod'
tester2dp.c:(.text.startup+0x20c9): undefined reference to `mpfr_modf'
lib/libsleef.so.3.6.0: undefined reference to `clock_gettime'
collect2: error: ld returned 1 exit status
This is with the master branch of sleef and GCC 5.3.0.
Full build logs: spack-build-out.txt spack-build-env.txt
According to https://stackoverflow.com/a/32649327/5828163 we just need to add -lrt
to the link line for glibc < 2.17. For the record, my glibc is 2.11.3, which is why I see this issue and others might not.
For now I was able to work around this by adding -DDISABLE_(FFTW|MPFR|SSL)
.
P.S. Are any sleef developers interested in helping to maintain our Spack build recipe for sleef? You don't need to be a Spack expert, it just gives us someone to ping when a user reports build issues or submits a PR to modify the build recipe.
Probably I am the only person who can help, but I am pretty busy this year. I will take a look in the next week.
For now I was able to work around this by adding
-DDISABLE_(FFTW|MPFR|SSL)
.
Spoke too soon, I'm still seeing this even when disabling these.
Hello, Please tell me about your build environment. Which operating system are you using? I think the libraries on your environment are too old. gcc-5.3 is pretty old, as you know.
I'm on Cray CNL5 with SUSE 11.3:
$ cat /etc/*-release
Cluster Manager v6.1
slave
LSB_VERSION="core-2.0-noarch:core-3.2-noarch:core-4.0-noarch:core-2.0-x86_64:core-3.2-x86_64:core-4.0-x86_64"
SUSE Linux Enterprise Server 11 (x86_64)
VERSION = 11
PATCHLEVEL = 3
Yes, the glibc on this system is ancient (2.11.3). I'm hoping we can patch things to make it work. Unfortunately this system can't be upgraded and I'm stuck on GCC 5 because I need to use CUDA 9.1. The system GCC (4.3.4) is much older than the one I'm using.
Indeed, clock_gettime()
appears in src/common/common.c
, src/libm-benchmarks/benchsvml.c
, src/dft-tester/measuredft.c
, and src/dft-tester/bench1d.c
. The first of these will always be compiled, I think, no matter what optional features you disable.
Have you actually tried adding -lrt
to the linker flags yet? It should be sufficient to do LDFLAGS='-lrt' cmake -S . -B my_builddir […]
.
If that works, here is how one project handled this situation by linking librt whenever it is present, and https://github.com/Z3Prover/z3/pull/1438/files is how another project handled it by linking librt only when it is required for clock_gettime()
. You could try patching Configure.cmake
in sleef and offer a PR if you think there are others who could benefit.
On a somewhat-related note, librt has disappeared completely in glibc 2.34, along with libdl and libpthread, with all of their functionality folded into the main libc. However, there are corresponding empty static libraries so that -lrt
, -ldl
, and -lpthread
still “work” for backwards compatibility.