Macaulay2 / M2

The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields.
https://macaulay2.com
347 stars 231 forks source link

Compilation fails on fedora 34 #2145

Closed pzinn closed 3 years ago

pzinn commented 3 years ago

compilation fails on fedora 34 with

[1/322] Building CXX object Macaulay2/e/CMakeFiles/M2-engine.dir/eigen.cpp.o
FAILED: Macaulay2/e/CMakeFiles/M2-engine.dir/eigen.cpp.o 
/usr/bin/c++  -I../../Macaulay2/e -I../../Macaulay2/d -I../../Macaulay2/c -IMacaulay2/d -I/usr/include/libxml2 -Iusr-host/include -I/usr/include/frobby -isystem /usr/include/flexiblas -isystem /usr/include/eigen3 -O2 -DNDEBUG -march=native -DNDEBUG -DOM_NDEBUG -DSING_NDEBUG -Wuninitialized -g3 -I/home/pzinn/M2/M2/BUILD/fedora/usr-host/include -I/home/pzinn/M2/M2/include -I/home/pzinn/M2/M2/BUILD/fedora/include -Wall -Wextra -Wfatal-errors -Wcast-qual -Wno-unused-parameter -Wno-attributes -Wno-cast-qual -Wno-sign-compare -Wno-unused-local-typedefs -Wno-deprecated-copy -Wno-unknown-pragmas -Wno-ignored-qualifiers -Wno-implicit-fallthrough -fopenmp -std=gnu++17 -MD -MT Macaulay2/e/CMakeFiles/M2-engine.dir/eigen.cpp.o -MF Macaulay2/e/CMakeFiles/M2-engine.dir/eigen.cpp.o.d -o Macaulay2/e/CMakeFiles/M2-engine.dir/eigen.cpp.o -c ../../Macaulay2/e/eigen.cpp
In file included from /home/pzinn/M2/M2/include/M2/math-include.h:31,
                 from ../../Macaulay2/e/eigen.cpp:3:
../../Macaulay2/e/mpreal.h: In copy constructor 'eigen_mpfr::mpreal::mpreal(const eigen_mpfr::mpreal&)':
../../Macaulay2/e/mpreal.h:582:27: error: no matching function for call to 'eigen_mpfr::mpreal::mpfr_srcptr(mpfr_srcptr)'
  582 |     mpfr_init2(mpfr_ptr(),mpfr_get_prec(u.mpfr_srcptr()));
      |                           ^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
[6/322] Building CXX object Macaulay2/e/CMakeFiles/M2-engine.dir/montableZZ.cpp.o
ninja: build stopped: subcommand failed.

I suspect this is related to: https://github.com/advanpix/mpreal/issues/7 but am not competent to fix myself.

antonleykin commented 3 years ago

One solution that works (for me on fedora 34) is to

--enable-build-libraries=mpfr

when building with autotools, which currently forces a build of mpfr-4.0.2.

@mikestillman points out that cmake builds mpfr-4.1.0 if forced. Perhaps @mahrud could change this, which would be the most sensible solution at the moment. The alternative is to patch mpfr-4.1.0, but it may be best to wait for the outcome of this issue

I suspect this is related to: advanpix/mpreal#7 but am not competent to fix myself.

DanGrayson commented 3 years ago

I've just built M2 from scratch under Ubuntu 21.04, where mpfr 4.1.0 is in the system, using autotools, without commanding that mpfr be downloaded and built. So the theory that it's something about the version of mpfr is not supported.

ubuntu2104$ sudo apt-get install libmpfr-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libmpfr-dev is already the newest version (4.1.0-3build1).
d-torrance commented 3 years ago

Fedora patches mpfr quite a bit (https://src.fedoraproject.org/rpms/mpfr/blob/rawhide/f/allpatches), while Debian/Ubuntu do not (https://sources.debian.org/src/mpfr4/4.1.0-3/debian/patches/). Perhaps that's related?

antonleykin commented 3 years ago

The patch below fixes the mpfr-4.1.0 issue on fedora 34... at least for M2. The problem --- using mpfr_srcptr in a macro --- seems to be present on the version of mpfr in ubuntu 21.04 albeit in a different macro (perhaps a version of the one that involves the second modified line below).

Now gcc-11 is used on fedora, while gcc-10 is current on ubuntu. Perhaps this makes a difference?

[root@cos-3m2467 include]# diff mpfr.h mpfr.h-new
850c850
< #define MPFR_SRCPTR(x) ((mpfr_srcptr) (0 ? (x) : (mpfr_srcptr) (x)))
---
> #define MPFR_SRCPTR(x) ((::mpfr_srcptr) (0 ? (x) : (::mpfr_srcptr) (x)))
883c883
<       mpfr_srcptr _p = (b);                     \
---
>       ::mpfr_srcptr _p = (b);                 \
pzinn commented 3 years ago

thanks for looking into it. I tried your fix Anton (at least on my work comp, which runs Fedora 33 with mpfr-4.1.0-6.fc33.x86_64), and now I get

[1/533] Building C object Macaulay2/d/CMakeFiles/M2-interpreter.dir/gmp_aux.c.o
FAILED: Macaulay2/d/CMakeFiles/M2-interpreter.dir/gmp_aux.c.o 
/usr/bin/cc -DNDEBUG -DOM_NDEBUG -DSING_NDEBUG -I../../Macaulay2/d -I../../Macaulay2/e -I../../Macaulay2/c -IMacaulay2/d -I/usr/include/libxml2 -Iusr-host/include -I../../Macaulay2/system -isystem /usr/include/flexiblas -O2 -DNDEBUG -march=native -Wuninitialized -g3 -I/home/pzinn/M2/M2/BUILD/fedora/usr-host/include -I/home/pzinn/M2/M2/include -I/home/pzinn/M2/M2/BUILD/fedora/include -Wall -Wextra -Wfatal-errors -Wcast-qual -Wno-unused-parameter -Wno-attributes -Wno-cast-qual -Wno-sign-compare -Wno-uninitialized -Wno-unused -Wno-frame-address -fopenmp -std=gnu11 -MD -MT Macaulay2/d/CMakeFiles/M2-interpreter.dir/gmp_aux.c.o -MF Macaulay2/d/CMakeFiles/M2-interpreter.dir/gmp_aux.c.o.d -o Macaulay2/d/CMakeFiles/M2-interpreter.dir/gmp_aux.c.o -c ../../Macaulay2/d/gmp_aux.c
In file included from /home/pzinn/M2/M2/include/M2/math-include.h:31,
                 from ../../Macaulay2/d/gmp_aux.c:3:
../../Macaulay2/d/gmp_aux.c: In function ‘mpfr_hash’:
../../Macaulay2/d/gmp_aux.c:20:12: error: expected expression before ‘::’ token
   20 |   if (0 != mpfr_sgn(x))
      |            ^~~~~~~~

I'll try on my fedora 34 laptop tonight.

pzinn commented 3 years ago

on fedora 34 laptop:

[1/245] Building C object Macaulay2/e/CMakeFiles/M2-engine.dir/complex.c.o
FAILED: Macaulay2/e/CMakeFiles/M2-engine.dir/complex.c.o 
/usr/bin/cc -DNDEBUG -DOM_NDEBUG -DSING_NDEBUG -I../../Macaulay2/e -I../../Macaulay2/d -I../../Macaulay2/c -IMacaulay2/d -I/usr/include/libxml2 -Iusr-host/include -I/usr/include/frobby -isystem /usr/include/flexiblas -isystem /usr/include/eigen3 -O3 -DNDEBUG -march=native -Wuninitialized -g3 -I/home/pzinn/M2/M2/BUILD/fedora/usr-host/include -I/home/pzinn/M2/M2/include -I/home/pzinn/M2/M2/BUILD/fedora/include -Wall -Wextra -Wfatal-errors -Wcast-qual -Wno-unused-parameter -Wno-attributes -Wno-cast-qual -Wno-sign-compare -Wno-unused-local-typedefs -fopenmp -std=gnu11 -MD -MT Macaulay2/e/CMakeFiles/M2-engine.dir/complex.c.o -MF Macaulay2/e/CMakeFiles/M2-engine.dir/complex.c.o.d -o Macaulay2/e/CMakeFiles/M2-engine.dir/complex.c.o -c ../../Macaulay2/e/complex.c
In file included from /home/pzinn/M2/M2/include/M2/math-include.h:31,
                 from Macaulay2/d/engine-exports.h:20,
                 from ../../Macaulay2/e/complex.h:13,
                 from ../../Macaulay2/e/complex.c:3:
../../Macaulay2/e/complex.c: In function ‘mpfc_init_set’:
../../Macaulay2/e/complex.c:11:3: error: expected expression before ‘::’ token
   11 |   mpfr_init_set(result->re, a->re, GMP_RNDN);
      |   ^~~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.
[4/245] Building C object Macaulay2/e/CMakeFiles/M2-engine.dir/table.c.o
ninja: build stopped: subcommand failed.
antonleykin commented 3 years ago

Oops... The previous changes worked only because I resumed the built from the point it broke: only C++ files were left to compile. The following works for a build from scratch.

[include]# diff mpfr.h-old mpfr.h
850c850,855
< #define MPFR_SRCPTR(x) ((mpfr_srcptr) (0 ? (x) : (mpfr_srcptr) (x)))
---
> #if defined (__cplusplus)
> #define MPFR_SRCPTR_TYPE ::mpfr_srcptr
> #else
> #define MPFR_SRCPTR_TYPE mpfr_srcptr
> #endif
> #define MPFR_SRCPTR(x) ((MPFR_SRCPTR_TYPE) (0 ? (x) : (MPFR_SRCPTR_TYPE) (x)))
883c888
<       mpfr_srcptr _p = (b);                     \
---
>       MPFR_SRCPTR_TYPE _p = (b);                      \
pzinn commented 3 years ago

Hurray! I can run / compile M2 for the first time in months! (works on both fedora 33 and 34)

DanGrayson commented 3 years ago

That seems to be a patch to mpfr. What about a patch to Macaulay2, instead?

haerski commented 3 years ago

Can confirm the same issue with Arch with mpfr 4.1.0.p13-1. It builds fine when if I downgrade to the unpatched version, or if I build mpfr separately.

I tried the renaming method suggested in https://github.com/advanpix/mpreal/pull/8, but this breaks compatibility with #include <unsupported/Eigen/MPRealSupport>...

pzinn commented 3 years ago

so is this issue resolved? It seems to compile fine now on my machine w/o the mpfr.h hack, but maybe I'll wait for Anton to confirm before closing.