cpmech / gosl

Linear algebra, eigenvalues, FFT, Bessel, elliptic, orthogonal polys, geometry, NURBS, numerical quadrature, 3D transfinite interpolation, random numbers, Mersenne twister, probability distributions, optimisation, differential equations.
BSD 3-Clause "New" or "Revised" License
1.83k stars 145 forks source link

Autodetect Homebrew GCC and properly populate LD_FLAGS on MacOS #27

Closed IronhandedLayman closed 6 years ago

IronhandedLayman commented 6 years ago

When attempting an install of gosl on MacOS using the instructions in the doc directory I get the following issue:

=== compiling num/qpck =============================================================
/Users/nathaniel.dean/golang/src/github.com/cpmech/gosl/num/qpck
# github.com/cpmech/gosl/num/qpck
ld: warning: directory not found for option '-L/usr/local/Cellar/gcc/7.3.0_1/lib/gcc/7/'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is because the CGO Darwin flags in num/qpck/flags.go specifically point to a particular version of GCC that according to Homebrew is out of date. It is annoyingly difficult to get Homebrew to install multiple versions of a package, and besides this should be detected somehow. Maybe a go generate line to detect gcc version and populate? Maybe setting CGO_LDFLAGS from the all.bash script? The current fix (editing line 12 of flags.go) requires a codehack to get everything to build and I think this user experience can be drastically improved.

cpmech commented 6 years ago

Agreed! I'll look into it again. For reference, this issue was briefly mentioned here as well: https://github.com/cpmech/gosl/issues/26

cpmech commented 6 years ago

Done!

My all.bash script should now autodetect the GCC version on macOS.

See changes here: https://github.com/cpmech/gosl/commit/c34297e62614b37a77d9a492fb7386f44e35fdb9

NOTE: I've tested with the most recent HomeBrew packages.

Thanks for your suggestion.