mmottl / gsl-ocaml

OCaml bindings to the GSL (GNU Scientific Library).
Other
36 stars 10 forks source link

build problems on macos #34

Closed nilsbecker closed 1 year ago

nilsbecker commented 2 years ago

After some update cycles of xcode etc, i tried reinstalling gsl-ocaml but it doesn't anymore.

I ended up getting the source with opam source and running dune build in the source directory. This gives the following error:

dune build @install
File "src/dune", line 1, characters 0-1096:
 1 | (library
 2 |   (public_name gsl)
 3 |   (c_names
....
56 |   (c_library_flags (:include c_library_flags.sexp))
57 |   (libraries bigarray)
58 | )
ld: file not found: @rpath/libquadmath.0.dylib for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I then tried to look for this shared library. I found some copies installed by homebrew:

find /usr/local -name libquadmath.0.dylib
/usr/local/gfortran/lib/libquadmath.0.dylib
/usr/local/Cellar/gcc/12.2.0/lib/gcc/current/libquadmath.0.dylib
/usr/local/Cellar/gcc/12.2.0/lib/gcc/12/libquadmath.0.dylib

The latter are part of homebrew-installed gcc. however, the system compiler is clang, and that is used during the installation process as far as i can tell. gcc is in fact clang as usual on macos.

find /System/Library/Frameworks/ -name libquadmath*

finds nothing (I don't know if that's the right place to look).

I also tried brew reinstall gsl and unlink followed by relink, without success.

What could be the problem?

macos 12.6, current Xcode.

nilsbecker commented 2 years ago

log.txt

nilsbecker commented 2 years ago

aha!

GSL_CBLAS_LIB=-L/usr/local/opt/openblas/lib/ -lopenblas

if i remove this environment setting, i can successfully dune build gsl. however, i would like to continue using openblas.

next, in order to still use openblas, i tried to brew reinstall openblas. this did not help. next, i tried brew unlink openblas && brew link openblas. this gave a potentially troublesome warning:

Unlinking /usr/local/Cellar/openblas/0.3.21... 0 symlinks removed.
Warning: Refusing to link macOS provided/shadowed software: openblas
For compilers to find openblas you may need to set:
  export LDFLAGS="-L/usr/local/opt/openblas/lib"
  export CPPFLAGS="-I/usr/local/opt/openblas/include"

For pkg-config to find openblas you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openblas/lib/pkgconfig"

i next tried setting all of these env vars. however, this did not produce a working build.

what can i do to make linking with openblas work again?

nilsbecker commented 2 years ago

i now tried reinstalling openblas from source with brew reinstall -s openblas. this showed a message containing CC=gcc-12 FC=gfortran suggesting that the homebrew installed compilers were used. still, no luck with dune build gsl afterwards

nilsbecker commented 2 years ago

it seems this is really a problem of properly installing openblas on my system -- still i would be grateful for advice. it used to work on this system before, but now i'm kind of lost

nilsbecker commented 2 years ago

I got a bit further. Openblas is trying to link libquadmath.0.dylib but that fails, although that shared library is installed in /usr/local/gfortran/lib. I tried manually creating a link to that library in /usr/local/lib. This indeed caused the library to be found by the linker; however now another library is reported as missing: libgcc_s.1.1.dylib. That libary is here:

/usr/local/Cellar/gcc/12.2.0/lib/gcc/12/libgcc_s.1.1.dylib
/usr/local/Cellar/gcc/12.2.0/lib/gcc/current/libgcc_s.1.1.dylib

It appears the homebrew installation of gcc puts libraries in places where they aren't found by the clang toolchain used to build gsl-ocaml. Is this a bug in the homebrew package for gcc?

nilsbecker commented 2 years ago

I was able to work around the issue, as follows:

export GSL_CBLAS_LIB=-L/usr/local/opt/openblas/lib/ -lopenblas -L/usr/local/gfortran/lib
opam install gsl

By specifying the gfortran library directory explicitly, the required shared libraries are then found and i can successfully install gsl-ocaml.

The last -L include directive was not necessary when I installed gsl-ocaml previously on this machine, so I think this may still be a bug. Leaving it open for now.