fxcoudert / gfortran-for-macOS

GNU Fortran (and GCC) compilers for macOS
338 stars 56 forks source link

compile error on ARM Mac #12

Closed boccio-john closed 3 years ago

boccio-john commented 3 years ago

Fortran 90 code - compile works with gfortran 10.2 on intel Mac. However, when I try to do same compile using gfortran 11.0 on ARM Mac (installed using simple package over 10.2 version), it fails with message:

ld:library not found for -lm collect2: error: ld returned 1 exit value

compile command is:

/usr/local/gfortran/bin/gfortran treecode.f90 treegrav.f90 treeio.f90 treeload.f90 -o treecode

fxcoudert commented 3 years ago

Do you have the command-line tools installed (with xcode-select --install)?

boccio-john commented 3 years ago

Yes, they are installed.

Thanks.

On Dec 2, 2020, at 4:27 PM, FX Coudert notifications@github.com wrote:

xcode-select --install

martin-frbg commented 3 years ago

Quoting isuruf from https://github.com/xianyi/OpenBLAS/issues/3032#issuecomment-743805371

It looks like gfortran was compiled with /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk and gfortran saves this location into its binary. You have /Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk which becomes a problem. A workaround is to do export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk

and that suggestion later refined to export MACOSX_DEPLOYMENT_TARGET=11.0

boccio-john commented 3 years ago

Thanks. That worked. I am a physicist compiling fortran 90 code to do galaxy-galaxy collisions. I am not a UNIX expert at all. I just issued the export command in the terminal window before I ran the compile operation. Is there somewhere I should enter the export command so that is always active? Thanks for any help. By the way it is running extremely fast on the MacBook Air M1 system.

sholmas commented 3 years ago

macOS 11.1 is now available to all users, it solved this issue for me after reinstalling the command line tools (using xcode-select --install).

boccio-john commented 3 years ago

Thanks. I just found that out also this evening.

Sent from John Boccio's iPad

On Dec 17, 2020, at 9:51 PM, Stian Holmas notifications@github.com wrote:

 macOS 11.1 is now available to all users, it solved this issue for me after reinstalling the command line tools (using xcode-select --install).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

fxcoudert commented 3 years ago

macOS 11.1 and the command-line tools 12.3 fix this issue. I will try to make my next build more robust.

iains commented 3 years ago

This issue was referenced in a discussion of static linking:

e.g *lib: %{!static-libgfortran: -lquadmath } %{static-libgfortran: libquadmath.a%s} %(libgcc) %(liborig)

beausoleilmo commented 3 years ago

About lquadmath, when trying to install RcppArmadillo in R, I get this message:

ld: library not found for -lquadmath
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [RcppArmadillo.so] Error 1
ERROR: compilation failed for package ‘RcppArmadillo’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo’

I already modified the line in Makeconf FLIBS = -L/usr/local/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm (see here https://stackoverflow.com/questions/23916219/os-x-package-installation-depends-on-gfortran-4-8)

to specify the "proper" location of the gcc, but lquadmath seems it's not working at all. Do you have a quick workaround?

iains commented 3 years ago

for Arm64, there is no libquadmath - theres no REAL*16 equivalent on the platform at present. This means that we need a configure change to omit the "-lquadmath" from the spec.

You should be able to hack around it in the short-term by editing /path/to/compiler/lib/libgfortran.spec and removing the "-lquadmath" from the last line.

iains commented 3 years ago

(for Arm64 on Darwin)