M2 icon indicating copy to clipboard operation
M2 copied to clipboard

CMake build problem(s)

Open ggsmith opened this issue 1 year ago • 15 comments

When attempting to build Macaulay2 from source, I encountered the following fatal error:

.../M2/M2/Macaulay2/e/aring-zzp-flint.hpp:121:14: fatal error: use of undeclared identifier 'nmod_neg'
    result = nmod_neg(a, mModulus);

I was unable to match this error message with any of the common issues and errors related to the CMake build.

ggsmith avatar Feb 03 '24 19:02 ggsmith

See #2973. This looks like one of the build errors we were getting for a while when we added support for FLINT 3.

Which version of FLINT are you using? Which branch are you building?

d-torrance avatar Feb 04 '24 00:02 d-torrance

Assuming you are using Brew's flint, it should be the most recent, but you can check with:

brew info flint

And if it's less than 3 update it with:

brew update flint

mahrud avatar Feb 04 '24 05:02 mahrud

Actually, I thought in that PR we made sure M2 was still compiling fine with older versions of flint. Are you building from the development branch?

mahrud avatar Feb 04 '24 05:02 mahrud

I already have flint: stable 3.0.1 (bottled).

I tried compiling from source in the master branch and the development branch. Both appeared to produce the same fatal error.

ggsmith avatar Feb 04 '24 18:02 ggsmith

I'm wondering if somehow HAVE_FLINT_NMOD_H didn't get set. If it isn't, then you wouldn't be including the right header that declares nmod_neg in FLINT 3. Does that variable appear anywhere in CMakeCache.txt?

I'm not very familiar with cmake, but maybe it's still using some cached configuration you used before we added FLINT 3 support?

d-torrance avatar Feb 04 '24 19:02 d-torrance

In CMakeCache.txt, I found HAVE_FLINT_NMOD_H:INTERNAL=. What should it be set to?

ggsmith avatar Feb 04 '24 19:02 ggsmith

Might be worth running

cmake -U*FLINT* .

This will unset any flint related variables and detect them again. (The correct value should be 1, but this should definitely be auto detected, not set manually)

mahrud avatar Feb 04 '24 19:02 mahrud

I tried

cmake -U*FLINT* .

The output was just

no matches found: -U*FLINT*

ggsmith avatar Feb 04 '24 20:02 ggsmith

Ah, sorry, you're using zshell, use this instead:

cmake -U"*FLINT*" .

mahrud avatar Feb 05 '24 04:02 mahrud

This command ran. It included some warnings such as

-- Could NOT find MSolve (missing: MSOLVE_INCLUDE_DIR MSOLVE_LIBRARIES) (Required is at least version "0.4.0")
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY) (Required is at least version "1.10")

-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY) 

but appear to run ending with

-- Build files have been written to: /Users/ggs/M2/M2/BUILD/build

However, this didn't change the HAVE_FLINT_NMOD_H:INTERNAL= in CMakeCache.txt and ninja still terminates with the same fatal error.

ggsmith avatar Feb 05 '24 15:02 ggsmith

I looked at Greg's laptop, the problem seemed to be that when building the test file to check whether flint has nmod.h, the compiler for the test script can't find gmp.h!

Greg, could you apply this patch:

diff --git a/M2/cmake/check-libraries.cmake b/M2/cmake/check-libraries.cmake
index e7bb883f53..c17a692a04 100644
--- a/M2/cmake/check-libraries.cmake
+++ b/M2/cmake/check-libraries.cmake
@@ -357,7 +357,7 @@ else()
 endif()
 
 if(FLINT_FOUND)
-  set(CMAKE_REQUIRED_INCLUDES "${FLINT_INCLUDE_DIR}")
+  set(CMAKE_REQUIRED_INCLUDES "${FLINT_INCLUDE_DIR};${MP_INCLUDE_DIRS}")
   check_include_files(flint/nmod.h HAVE_FLINT_NMOD_H)
 else()
   unset(HAVE_FLINT_NMOD_H CACHE)

and then run:

cmake -U"*FLINT*" .
grep NMOD CMakeCache.txt

Hopefully that fixes the problem.

If it doesn't, the steps to see the (hopefully new) error are to run:

cmake -U"*FLINT*" --debug-trycompile .

and then look into the directories under CMakeFiles/CMakeScratch. One of them will contain HAVE_FLINT_NMOD_H.c, and running ninja in that subdirectory should show the error.

mahrud avatar Feb 05 '24 20:02 mahrud

My zsh prompt does not seem to like the proposed patch. Specifically, I get the error message zsh: parse error near `else'

ggsmith avatar Feb 05 '24 20:02 ggsmith

Weird, but the diff is just adding ;${MP_INCLUDE_DIRS} to line 360 so you could do it manually.

mahrud avatar Feb 05 '24 21:02 mahrud

As suggested, I added the patch manually. As far as I can tell, this did not fix the problem:

~/M2/M2/BUILD/build % grep NMOD CMakeCache.txt
HAVE_FLINT_NMOD_H:INTERNAL=

Furthermore, running ninja in an appropriate subdirectory gives the following error:

~/M2/M2/BUILD/build/CMakeFiles/CMakeScratch/TryCompile-Yhrf1h % ninja
[1/2] Building C object CMakeFiles/cmTC_180ab.dir/HAVE_FLINT_NMOD_H.c.o
FAILED: CMakeFiles/cmTC_180ab.dir/HAVE_FLINT_NMOD_H.c.o 
/Library/Developer/CommandLineTools/usr/bin/cc  -I/opt/homebrew/opt/flint/include -I/Users/ggs/M2/M2/BUILD/build/CMakeFiles/CMakeScratch/TryCompile-Yhrf1h/{MP_INCLUDE_DIRS} -std=gnu11 -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.2.sdk -MD -MT CMakeFiles/cmTC_180ab.dir/HAVE_FLINT_NMOD_H.c.o -MF CMakeFiles/cmTC_180ab.dir/HAVE_FLINT_NMOD_H.c.o.d -o CMakeFiles/cmTC_180ab.dir/HAVE_FLINT_NMOD_H.c.o -c /Users/ggs/M2/M2/BUILD/build/CMakeFiles/CMakeScratch/TryCompile-Yhrf1h/HAVE_FLINT_NMOD_H.c
In file included from /Users/ggs/M2/M2/BUILD/build/CMakeFiles/CMakeScratch/TryCompile-Yhrf1h/HAVE_FLINT_NMOD_H.c:2:
In file included from /opt/homebrew/opt/flint/include/flint/nmod.h:22:
In file included from /opt/homebrew/opt/flint/include/flint/ulong_extras.h:25:
In file included from /opt/homebrew/opt/flint/include/flint/limb_types.h:15:
/opt/homebrew/opt/flint/include/flint/flint.h:28:10: fatal error: 'gmp.h' file not found
#include <gmp.h>
         ^~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.

ggsmith avatar Feb 05 '24 22:02 ggsmith

@ggsmith @mahrud Is this fixed? What was the problem?

mikestillman avatar Jun 21 '24 12:06 mikestillman