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

1.17 source build fails on macos #1767

Closed mikestillman closed 3 years ago

mikestillman commented 3 years ago

On MacOS catalina, compiling with appleclang, I did a brew upgrade, and it installed flint 2.7.0. After that, a fresh autotools build failed (many errors related to fmpz...). This is on release-1.17 (with my pull request changes, but those changes are not relevant for this problem).

(edit: the build failures occurred during building factory). (edit2: same issue occurs on cmake build)

mikestillman commented 3 years ago

If I downgrade brew flint to 2.6.0, the cmake build works until the linking of M2 step. Now I get the error (after the long line for linking M2):

ld: library not found for -licudata
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

This appears to be related to libboost (which also got updated to 1.75 when I did the brew upgrade...). @mahrud Any suggestions?

mahrud commented 3 years ago

The problem with flint 2.7.0 is that the new flint has a changed interface and the version of factory that we build is not yet compatible with it. We would need to build the new factory first, but given the complications that it will cause on various systems (e.g. if the flint is older than factory or factory is older than flint), it's probably just easier for you to do:

brew install flint@2.6.0

Not sure about the icudata .. why do you think it's related to boost?

mikestillman commented 3 years ago

What is libicudata? I don't think I know it.

mikestillman commented 3 years ago

update: with flint@2.6.0, autotools build makes it to the examples fine. The cmake build fails, since it can't find libicudata (but everything builds fine to that point, just fails at linking M2). When did we start linking with libicudata? Is it a mistake?

mahrud commented 3 years ago

Could you provide more information? The compiler or the output of the cmake maybe? Github actions is compiling fine with boost-1.74 on Catalina. Perhaps you need to rebuild certain libraries after upgrading.

mahrud commented 3 years ago

Looked into it a bit. It's a known issue of the brew package for boost 1.75: https://github.com/Homebrew/homebrew-core/pull/67615, it should be resolved soon.

On my system, the packaged libboost_regex.so is dynamically linked with few libraries that deal with unicode (icu is International Components for Unicode):

[mahrud@noether clang]$ ldd /lib64/libboost_regex.so.1.69.0
    libicudata.so.65 => /lib64/libicudata.so.65 (0x00007f036d651000)
    libicui18n.so.65 => /lib64/libicui18n.so.65 (0x00007f036d34a000)
    libicuuc.so.65 => /lib64/libicuuc.so.65 (0x00007f036d162000)
...

In particular, they are requirements of libboost_regex. Could you run otool on your libboost_regex? Probably on your system you'd need to add the path for libicudata to your LDFLAGS. I think it comes in the brew package icu4c, but it may be elsewhere on your system also.

The reason you don't get the same issue with autotools is that it forces using static libraries, which in general isn't a good idea, as I explained in #1737. On the other hand, this means that for the short term there is an easy solution: use the same workaround as in #1737 to link with boost statically:

cmake -U*Boost* -DBoost_USE_STATIC_LIBS=on .
DanGrayson commented 3 years ago

The reason you don't get the same issue with autotools is that it forces using static libraries,

That's only if you make a dmg distribution file, which Mike is probably not doing.

mikestillman commented 3 years ago

I tried this:

cmake -U*Boost* -DBoost_USE_STATIC_LIBS=on .

but get the same error (I am on appleclang 12.0.0, macos catalina):

FAILED: usr-dist/x86_64-Darwin-MacOS-10.15.7/bin/M2-binary 
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -O2 -g -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -mmacosx-version-min=10.15 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -march=native -g --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -L/Users/mike/src/M2-release-1.17/M2/BUILD/mike/builds.tmp/cmake-appleclang/usr-host/lib 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-Darwin-MacOS-10.15.7/bin/M2-binary  /usr/local/lib/libboost_stacktrace_addr2line-mt.a  Macaulay2/e/libM2-engine.a  /usr/local/lib/libboost_regex-mt.a  -licudata  -licui18n  -licuuc  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/local/lib/libntl.dylib  /usr/local/lib/libmpfr.dylib  /usr/local/lib/libgmpxx.dylib  /usr/local/lib/libgmp.dylib  /usr/local/lib/libgc.dylib  -framework  Accelerate  -lm  -ldl  /usr/lib/libxml2.dylib  /usr/local/opt/readline/lib/libreadline.dylib  /usr/local/opt/readline/lib/libhistory.dylib  /usr/local/lib/libgdbm.dylib  /usr/local/lib/libatomic_ops.a  /usr/local/lib/libomp.dylib && cd /Users/mike/src/M2-release-1.17/M2/BUILD/mike/builds.tmp/cmake-appleclang/Macaulay2/bin && /usr/local/Cellar/cmake/3.19.2/bin/cmake -E echo --\ Linked\ libraries: && DYLD_LIBRARY_PATH=/Users/mike/src/M2-release-1.17/M2/BUILD/mike/builds.tmp/cmake-appleclang/usr-host/lib: /usr/bin/otool -L /Users/mike/src/M2-release-1.17/M2/BUILD/mike/builds.tmp/cmake-appleclang/usr-dist/x86_64-Darwin-MacOS-10.15.7/bin/M2-binary && /usr/local/Cellar/cmake/3.19.2/bin/cmake -E echo --\ INSTALL_RPATH:\ /usr/local/lib/Macaulay2/lib
ld: library not found for -licudata
clang: error: linker command failed with exit code 1 (use -v to see invocation)
mahrud commented 3 years ago

Did you try installing icu4c?

Regardless, let's just wait for https://github.com/Homebrew/homebrew-core/issues/67427 to be fixed. This is legitimately a problem with boost (see https://github.com/boostorg/boost_install/issues/47), so I don't think we should do anything.

... /usr/local/lib/libboost_regex-mt.a  -licudata  -licui18n  -licuuc ...
mikestillman commented 3 years ago

The only issue about waiting is I can't build M2 currently under cmake. I'll continue to look for workarounds. It appears that I cannot back off this version of boost in brew easily (well, it complained when I tried).

mikestillman commented 3 years ago

I have a couple more things to try though.

mahrud commented 3 years ago

Did you try downgrading boost? I'm not sure about the command, but brew install boost@1.60.0 might work.

carlocab commented 3 years ago

If you don't mind the compile time, you can use the patched version of boost at https://github.com/Homebrew/homebrew-core/pull/67615. One way to do this might be

cd $(brew --repo homebrew/core)
gh pr checkout 67615
HOMEBREW_NO_AUTO_UPDATE=1 brew install -sv boost

The -v flag isn't necessary; I just find it makes long compile times less painful. (Leaving out the -v flag hides all compilation output.)

You may wish to avoid unqualified brew upgrades in the meantime so that brew doesn't accidentally switch out your patched version of boost. (You can probably also avoid this with brew pin boost.) Don't forget to switch your core repo back to master when you're done.

That said, I've resolved the CI failure in the PR locally, so I'm hoping the patched version of boost should be on the master branch tomorrow.

carlocab commented 3 years ago

FYI, https://github.com/Homebrew/homebrew-core/pull/67615 has been merged, so this should be fixed for Homebrew boost.

mikestillman commented 3 years ago

Thanks very much!

mahrud commented 3 years ago

Does your build work fine now, @mikestillman?

mikestillman commented 3 years ago

Yes, the cmake build on macos, using apple clang, now builds the executable correctly (with boost 1.75.0). I did have to uninstall flint on brew though, as it is a breaking change that causes factory to not compile, I believe.

mahrud commented 3 years ago

Great!

I presume this issue can be closed then, since Macaulay2 is not compatible with flint 2.7.0 without a decent amount of changes, and that's for another issue. For the time being, you can pin 2.6.0:

brew install flint@2.6.0
brew pin flint@2.6.0
carlocab commented 3 years ago

Unfortunately, that method of installing it won't work, as there is no flint@2.6[.0] formula.

However, you can set one up in your own tap using the following:

brew tap-new <GitHub username>/<tap name>
brew extract --version=2.6.3 flint <GitHub username>/<tap name>
brew install flint@2.6.3

That will build flint 2.6.3 from source. If you wish to build a bottle for it, you can have a look at https://brew.sh/2020/11/18/homebrew-tap-with-bottles-uploaded-to-github-releases/. This will allow you to build the formula from source on a GitHub runner instead.

brew tap-new will create a new git repo in $(brew --repo <GitHub username>/<tap name>), and brew extract will create a formula called flint@2.6.3 in that repository. You can feel free to edit that formula as you please. This might help: https://docs.brew.sh/Formula-Cookbook

mahrud commented 3 years ago

Ah, I didn't realize that, but that trick is very helpful for when I get around to #1166 again. Thank you!

carlocab commented 3 years ago

Sure. In case you aren't able to get it into homebrew/core for some reason, you're also free to host your own tap for a Macaulay2 formula. That will allow you to set up formulae for your own custom dependencies (e.g. flint2.6, which isn't provided by Homebrew), but also use any dependencies already provided by Homebrew. (Caveat: relying on Homebrew for dependencies doesn't work too well if you need fine control over which version you use.)

For example, you can create a repo owned by the Macaulay2 organisation called homebrew-M2 to host this tap. Then, your users can install Macaulay2 by doing

brew tap Macaulay2/M2
brew install Macaulay2

You can read the docs I linked above for instructions on how to build bottles (pre-built binaries) for your formulae.

Feel free to ping me if you have any questions.