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

CMake build failing on WSL2 #1520

Closed jchen419 closed 4 years ago

jchen419 commented 4 years ago

I am unable to build M2 via CMake on a fresh WSL2 install. After repeated attempts, it seems the problem always comes in the same step of building the binary, as shown below:

jchen@DESKTOP-B2KDSAV:~/jchen419-M2/M2/BUILD/build$ ninja
ninja: warning: premature end of file; recovering
[112/322] Linking CXX executable Macaulay2/e/M2-unit-tests
FAILED: Macaulay2/e/M2-unit-tests Macaulay2/e/M2-unit-tests[1]_tests.cmake
: && /usr/bin/c++  -O3 -DNDEBUG  -march=native -g3 -L/home/jchen/jchen419-M2/M2/BUILD/build/usr-host/lib -fopenmp Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/M2-cpp-replacement.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/M2-replacement.c.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/M2mem-replacement.c.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/ARingZZTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/ARingZZpTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/ARingGFTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/ARingQQFlintTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/ARingQQGmpTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/ARingRRTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/ARingCCTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/ARingRRRTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/ARingCCCTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/RingZZTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/RingZZpTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/RingQQTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/RingCCCTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/RingRRRTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/RingTowerTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/DMatZZpTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/ResTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/PointArray.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/SubsetTest.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/basics-test.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/fromStream.cpp.o Macaulay2/e/CMakeFiles/M2-unit-tests.dir/unit-tests/testMain.cpp.o  -o Macaulay2/e/M2-unit-tests  Macaulay2/e/libM2-engine.a  usr-host/lib/libgc.a  usr-host/lib/libgtest.a  usr-host/lib/libgtest_main.a  -ldl  /usr/lib/x86_64-linux-gnu/libboost_regex.so.1.71.0  usr-host/lib/libgivaro.a  usr-host/lib/libmps.a  usr-host/lib/libmathicgb.a  usr-host/lib/libmathic.a  usr-host/lib/libmemtailor.a  usr-host/lib/libfrobby.a  usr-host/lib/libfactory.a  usr-host/lib/libflint.a  usr-host/lib/libntl.a  usr-host/lib/libmpfr.a  usr-host/lib/libgc.a  /usr/lib/x86_64-linux-gnu/libgmpxx.so  /usr/lib/x86_64-linux-gnu/libgmp.so  /usr/lib/x86_64-linux-gnu/libopenblas.so  /usr/lib/x86_64-linux-gnu/libxml2.so  /usr/lib/x86_64-linux-gnu/libreadline.so  /usr/lib/x86_64-linux-gnu/libhistory.so  /usr/lib/x86_64-linux-gnu/libgdbm.so  /usr/lib/x86_64-linux-gnu/libatomic_ops.a  /usr/lib/gcc/x86_64-linux-gnu/9/libgomp.so  /usr/lib/x86_64-linux-gnu/libpthread.so  usr-host/lib/libgtest.a  -lpthread && cd /home/jchen/jchen419-M2/M2/BUILD/build/Macaulay2/e && /usr/bin/cmake -D TEST_TARGET=M2-unit-tests -D TEST_EXECUTABLE=/home/jchen/jchen419-M2/M2/BUILD/build/Macaulay2/e/M2-unit-tests -D TEST_EXECUTOR= -D TEST_WORKING_DIR=/home/jchen/jchen419-M2/M2/BUILD/build/Macaulay2/e -D TEST_EXTRA_ARGS= -D TEST_PROPERTIES= -D TEST_PREFIX=unit-tests: -D TEST_SUFFIX= -D NO_PRETTY_TYPES=FALSE -D NO_PRETTY_VALUES=FALSE -D TEST_LIST=M2-unit-tests_TESTS -D CTEST_FILE=/home/jchen/jchen419-M2/M2/BUILD/build/Macaulay2/e/M2-unit-tests[1]_tests.cmake -D TEST_DISCOVERY_TIMEOUT=5 -P /usr/share/cmake-3.16/Modules/GoogleTestAddTests.cmake
/usr/bin/ld: Macaulay2/e/libM2-engine.a(interrupted.cpp.o): in function `system_interrupted()':
/home/jchen/jchen419-M2/M2/BUILD/build/../../Macaulay2/e/interrupted.cpp:6: undefined reference to `interrupts_interruptedFlag_id'
/usr/bin/ld: /home/jchen/jchen419-M2/M2/BUILD/build/../../Macaulay2/e/interrupted.cpp:6: undefined reference to `TS_Get_Local'
collect2: error: ld returned 1 exit status
[113/322] Linking CXX executable usr-dist/x86_64-Linux-Ubuntu-20.04/bin/M2-binary
FAILED: usr-dist/x86_64-Linux-Ubuntu-20.04/bin/M2-binary
: && /usr/bin/c++  -O3 -DNDEBUG  -march=native -g3 -L/home/jchen/jchen419-M2/M2/BUILD/build/usr-host/lib -fopenmp Macaulay2/d/CMakeFiles/M2-interpreter.dir/M2types.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/M2lib.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/M2mem.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/scclib.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/memdebug.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/debug.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/gmp_aux.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/gdbm_interface.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/arithmetic-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/atomic-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/M2-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/system-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/strings-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/varstrin-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/strings1-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/errio-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/vararray-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/ctype-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/nets-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/varnets-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/interrupts-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/pthread0-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/stdiop0-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/gmp-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/engine-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/xml-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/stdio0-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/parse-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/expr-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/stdio-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/stdiop-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/err-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/gmp1-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/tokens-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/getline-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/lex-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/parser-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/binding-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/basic-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/convertr-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/common-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/util-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/struct-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/classes-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/buckets-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/equality-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/hashtables-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/regex-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/sets-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/evaluate-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/mysqldummy-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/pthread-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/actors-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/actors2-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/actors3-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/actors4-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/xmlactors-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/actors5-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/actors6-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/threads-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/interface-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/interface2-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/texmacs-tmp.c.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/interp-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/version-tmp.cc.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/boost-regex.cpp.o Macaulay2/d/CMakeFiles/M2-interpreter.dir/xml-c.c.o Macaulay2/system/CMakeFiles/M2-supervisor.dir/supervisor.cpp.o Macaulay2/system/CMakeFiles/M2-supervisor.dir/m2file.cpp.o Macaulay2/system/CMakeFiles/M2-supervisor.dir/tests.cpp.o Macaulay2/bin/CMakeFiles/M2-binary.dir/timestamp.cpp.o Macaulay2/bin/CMakeFiles/M2-binary.dir/main.cpp.o Macaulay2/bin/CMakeFiles/M2-binary.dir/startup.c.o  -o usr-dist/x86_64-Linux-Ubuntu-20.04/bin/M2-binary  -Wl,-rpath,:::::::::::::::::::::::::::::::::::::::  /usr/lib/x86_64-linux-gnu/libboost_stacktrace_backtrace.so.1.71.0  Macaulay2/e/libM2-engine.a  -ldl  -lpthread  /usr/lib/x86_64-linux-gnu/libboost_regex.so.1.71.0  usr-host/lib/libgivaro.a  usr-host/lib/libmps.a  usr-host/lib/libmathicgb.a  usr-host/lib/libmathic.a  usr-host/lib/libmemtailor.a  usr-host/lib/libfrobby.a  usr-host/lib/libfactory.a  usr-host/lib/libflint.a  usr-host/lib/libntl.a  usr-host/lib/libmpfr.a  /usr/lib/x86_64-linux-gnu/libgmpxx.so  /usr/lib/x86_64-linux-gnu/libgmp.so  usr-host/lib/libgc.a  /usr/lib/x86_64-linux-gnu/libopenblas.so  /usr/lib/x86_64-linux-gnu/libxml2.so  /usr/lib/x86_64-linux-gnu/libreadline.so  /usr/lib/x86_64-linux-gnu/libhistory.so  /usr/lib/x86_64-linux-gnu/libgdbm.so  /usr/lib/x86_64-linux-gnu/libatomic_ops.a  /usr/lib/gcc/x86_64-linux-gnu/9/libgomp.so  /usr/lib/x86_64-linux-gnu/libpthread.so && cd /home/jchen/jchen419-M2/M2/BUILD/build/Macaulay2/bin && /usr/bin/cmake -E echo --\ Linked\ libraries: && LD_LIBRARY_PATH=/home/jchen/jchen419-M2/M2/BUILD/build/usr-host/lib: /usr/bin/ldd /home/jchen/jchen419-M2/M2/BUILD/build/usr-dist/x86_64-Linux-Ubuntu-20.04/bin/M2-binary && /usr/bin/cmake -E echo --\ INSTALL_RPATH:\ /usr/lib/x86_64-linux-gnu/Macaulay2/lib
/usr/bin/ld: Macaulay2/e/libM2-engine.a(franzi-interface.cpp.o): in function `rawGbBoolean':
/home/jchen/jchen419-M2/M2/BUILD/build/../../Macaulay2/e/franzi-interface.cpp:127: undefined reference to `gb(std::map<int, BRP, std::less<int>, std::allocator<std::pair<int const, BRP> > >&, int)'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
mahrud commented 4 years ago

Could you also put the result of cmake . here?

jchen419 commented 4 years ago

Sure thing:

jchen@DESKTOP-B2KDSAV:~/jchen419-M2/M2/BUILD/build$ cmake .
## Configure Macaulay2
     M2 version        = 1.16.0.2
     Git commit        = d12e1e0d4
     Install prefix    = /usr

     CMAKE_BUILD_TYPE  = Release
     BUILD_NATIVE      = ON
     BUILD_SHARED_LIBS = OFF
     BUILD_TESTING     = ON
     BUILD_DOCS        = OFF

     COVERAGE          = OFF
     PROFILING         = OFF

     DEVELOPMENT       = OFF
     EXPERIMENT        = OFF

## Host OS information
     ISSUE             = Ubuntu-20.04
     NODENAME          = DESKTOP-B2KDSAV
     OS REL            = Linux 4.19.128-microsoft-standard
     ARCH              = x86_64

## Staging area prefixes
     usr-host          = /home/jchen/jchen419-M2/M2/BUILD/build/usr-host
     common            = /home/jchen/jchen419-M2/M2/BUILD/build/usr-dist/common
     exec              = /home/jchen/jchen419-M2/M2/BUILD/build/usr-dist/x86_64-Linux-Ubuntu-20.04

## Compiler information
     C                 = GNU 9.3.0 (/usr/bin/cc)
     C++               = GNU 9.3.0 (/usr/bin/c++)

CHECK_START Checking for existing libraries and programs
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Could NOT find Sphinx (missing: SPHINX_EXECUTABLE)
CHECK_START Checking library compatibility
CHECK_PASS Libraries are compatible!
-- Submodule update
CHECK_FAIL Some components are missing
## Before building Macaulay2, rerun build-libraries and build-programs targets
## External components
     Need to build:
       Libraries       = N/A
       Programs        = 4ti2;cohomcalg;csdp;gfan;lrslib;nauty;normaliz;topcom
     Already built:
       Libraries       = BDWGC;MPFR;NTL;Flint;Factory;Frobby;cddlib;MPSolve;GTest;Memtailor;Mathic;Mathicgb;GLPK;Givaro;FFLAS_FFPACK
       Programs        = N/A

## Library information
     Linear Algebra    = /usr/lib/x86_64-linux-gnu/libopenblas.so
     MP Arithmetic     = /usr/lib/x86_64-linux-gnu/libgmpxx.so;/usr/lib/x86_64-linux-gnu/libgmp.so

-- Configuring done
-- Generating done
-- Build files have been written to: /home/jchen/jchen419-M2/M2/BUILD/build
jchen419 commented 4 years ago

(Not sure if this is relevant to the issue at hand, but I should also add that WSL2 has been consistently unstable for me with respect to RAM usage - the build process always causes the terminal to crash at least once. I believe this is because the process corresponding to the virtual OS (vmmem.exe) has runaway RAM usage, and is thus killed by Windows.)

mahrud commented 4 years ago

If you try running ninja M2-binary a few times, does the error change?

jchen419 commented 4 years ago

No, it's giving the same error right now. (Although on previous iterations, it has given an extremely long list of errors, which are all of the form /usr/bin/ld: in function ..., undefined reference to ...)

mahrud commented 4 years ago

Try doing:

rm Macaulay2/e/libM2-engine.a
rm Macaulay2/e/CMakeFiles/M2-engine.dir/interrupted.cpp.o
rm Macaulay2/e/CMakeFiles/M2-engine.dir/franzi-interface.cpp.o

Then run ninja M2-binary -j1, does the error change?

jchen419 commented 4 years ago

Nope, unfortunately still exactly the same error.

jchen419 commented 4 years ago

(I think -j1 might help with the RAM usage so that it doesn't crash during the build process, but it's never crashed for me on this step of building the binary.)

mahrud commented 4 years ago

I think what has happened is that the compilation crashed earlier, but somehow still produced a faulty file, so then later when it is being used to compile the binary some references are missing from it. Maybe try ninja clean then ninja M2-binary -j1.

jchen419 commented 4 years ago

So that seemed to work! RAM usage was steady, no crashes happened during the build process (though naturally it was slower), and I now have the binary file. It has some errors when starting M2 though - should I run ninja -j1 now?

mahrud commented 4 years ago

Try M2-core first, then you should be able to run M2.

For packages, too, add -j1. Feel free to close this if you don't run into any other issues. I'll add a FAQ entry about WSL2.

jchen419 commented 4 years ago

ninja -j1 worked (again with steady RAM usage), and now the binary works also. Thanks a lot for the help!! (I had thought that ninja was smart enough to recover from a crash, but apparently there can still be silent issues...)