Installing gfortran on MacBook with Apple M1 chip for use in R
Asked Answered
G

7

18

I'm on a MacBook Air with an Apple M1 chip, using macOS 11.6 Big Sur. I'm on R 4.1.1. I have Xtools and gfortran for the Apple M1 installed:

markwhite@marks-air ~ % which xcode-select
/usr/bin/xcode-select
markwhite@marks-air ~ % which gfortran
/usr/local/bin/gfortran

I am able to successfully install and run R—but installing some packages is giving me trouble:

> install.packages("mvtnorm")

  There is a binary version available but the source version is later:
        binary source needs_compilation
mvtnorm  1.1-2  1.1-3              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘mvtnorm’

trying URL 'https://cran.rstudio.com/src/contrib/mvtnorm_1.1-3.tar.gz'
Content type 'application/x-gzip' length 166421 bytes (162 KB)
==================================================
downloaded 162 KB

* installing *source* package ‘mvtnorm’ ...
** package ‘mvtnorm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c C_FORTRAN_interface.c -o C_FORTRAN_interface.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c miwa.c -o miwa.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c mvt.f -o mvt.o
make: /opt/R/arm64/bin/gfortran: No such file or directory
make: *** [mvt.o] Error 1
ERROR: compilation failed for package ‘mvtnorm’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/mvtnorm’
Warning in install.packages :
  installation of package ‘mvtnorm’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/fx/f46lfqf56_df59fvzgqhcbyr0000gn/T/RtmpfGZUAF/downloaded_packages’
> 

I believe the key line is: make: /opt/R/arm64/bin/gfortran: No such file or directory where it is looking in the wrong location for gfortran.

Confirming it is not there:

markwhite@marks-air ~ % cd /opt/R/arm64/
markwhite@marks-air arm64 % ls -la
total 0
drwxrwxr-x   8 root  wheel  256 Oct 18 11:04 .
drwxrwxr-x   3 root  wheel   96 May 13 20:40 ..
drwxrwxr-x  14 root  wheel  448 Oct 19 21:34 bin
drwxrwxr-x  29 root  wheel  928 May 13 20:47 include
drwxrwxr-x  20 root  wheel  640 May 14 18:50 lib
drwxrwxr-x   5 root  wheel  160 May 13 20:40 man
drwxr-xr-x   3 root  wheel   96 May 14 18:28 pkg
drwxrwxr-x   5 root  wheel  160 Oct 18 11:04 share
markwhite@marks-air arm64 % 

So, I just move gfortran from where it is to where R wants it to be:

markwhite@marks-air gfortran % sudo mv /usr/local/bin/gfortran /opt/R/arm64/bin
Password:
markwhite@marks-air gfortran % 

Then, I restart R and try again:

> install.packages("mvtnorm")

  There is a binary version available but the source version is later:
        binary source needs_compilation
mvtnorm  1.1-2  1.1-3              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘mvtnorm’

trying URL 'https://cran.rstudio.com/src/contrib/mvtnorm_1.1-3.tar.gz'
Content type 'application/x-gzip' length 166421 bytes (162 KB)
==================================================
downloaded 162 KB

* installing *source* package ‘mvtnorm’ ...
** package ‘mvtnorm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c C_FORTRAN_interface.c -o C_FORTRAN_interface.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c miwa.c -o miwa.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c mvt.f -o mvt.o
mvt.f:861:11:

  861 |       hs = sign( one, dh - r*dk )
      |           1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:862:11:

  862 |       ks = sign( one, dk - r*dh )
      |           1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:1155:16:

 1155 |             K = MOD( C(NP, MIN(NDIM-1,KLIM-1))*DBLE(K), DBLE(P(NP)) )
      |                1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:1215:17:

 1215 |             JP = 1 + J*R(J)
      |                 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:94:39:

   94 |       DOUBLE PRECISION COV(NL*(NL+1)/2), A(NL), B(NL), DL(NL), Y(NL)
      |                                       1
Warning: Array ‘cov’ at (1) is larger than limit set by ‘-fmax-stack-var-size=’, moved from stack to static storage. This makes the procedure unsafe when called recursively, or concurrently from multiple threads. Consider using ‘-frecursive’, or increase the ‘-fmax-stack-var-size=’ limit, or change the code to use an ALLOCATABLE array. [-Wsurprising]
mvt.f:86:33:

   86 |       SUBROUTINE MVSUBR( N, W, NF, F )
      |                                 1
Warning: Unused dummy argument ‘nf’ at (1) [-Wunused-dummy-argument]
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c mvtnorm-init.c -o mvtnorm-init.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c tvpack.f -o tvpack.o
tvpack.f:395:14:

  395 |          HS = SIGN( ONE, DH - R*DK )
      |              1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
tvpack.f:396:14:

  396 |          KS = SIGN( ONE, DK - R*DH )
      |              1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
tvpack.f:60:52:

   60 |       DOUBLE PRECISION ONE, ZRO, EPS, ZROS(3), HS(3), TVT, TVTL
      |                                                    1
Warning: Unused variable ‘hs’ declared at (1) [-Wunused-variable]
tvpack.f:60:45:

   60 |       DOUBLE PRECISION ONE, ZRO, EPS, ZROS(3), HS(3), TVT, TVTL
      |                                             1
Warning: Unused variable ‘zros’ declared at (1) [-Wunused-variable]
tvpack.f:220:72:

  220 |       END
      |                                                                        ^
Warning: ‘fin’ may be used uninitialized in this function [-Wmaybe-uninitialized]
tvpack.f:196:58:

  196 |       DOUBLE PRECISION EI(NL), AI(NL), BI(NL), FI(NL), FIN, ERR, KRNRDT
      |                                                          ^
note: ‘fin’ was declared here
clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o mvtnorm.so C_FORTRAN_interface.o miwa.o mvt.o mvtnorm-init.o tvpack.o -L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0'
ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mvtnorm.so] Error 1
ERROR: compilation failed for package ‘mvtnorm’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/mvtnorm’
Warning in install.packages :
  installation of package ‘mvtnorm’ had non-zero exit status

The downloaded source packages are in
    ‘/private/var/folders/fx/f46lfqf56_df59fvzgqhcbyr0000gn/T/RtmpmlhiE8/downloaded_packages’
> 

It looks like it is still getting confused with directory paths, or mv didn't actually move what it needed to move.

How can I point R to the correct directory or install gfortran in the correct directory?

I know this problem is a mess right now, I've looked at other threads, but can't quite get anything anyone suggests to work.

Gonsalves answered 20/10, 2021 at 2:54 Comment(2)
For others who find their way here: I have written up instructions appropriate for both Big Sur and Monterey here. The details on Monterey aren't fundamentally different but there are some complications.Eclogite
I think you installed the gfortran using Homebrew and did not admit your sin.Reo
G
9

I deleted everything gfortran related and started over.

I downloaded the .tar.xz file here using the browser, which dumped the file into my Downloads folder. I double-clicked it to unpack it.

I moved that directory to where R wanted it:

markwhite@marks-air ~ % sudo mv Downloads/gfortran /opt/R/arm64/

Then I restarted R and tried again. It threw me some Fortran compilation messages—which I will not pretend to comprehend here—but it successfully installed:

> install.packages("mvtnorm")

  There is a binary version available but the source version is later:
        binary source needs_compilation
mvtnorm  1.1-2  1.1-3              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘mvtnorm’

trying URL 'https://cran.rstudio.com/src/contrib/mvtnorm_1.1-3.tar.gz'
Content type 'application/x-gzip' length 166421 bytes (162 KB)
==================================================
downloaded 162 KB

* installing *source* package ‘mvtnorm’ ...
** package ‘mvtnorm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c C_FORTRAN_interface.c -o C_FORTRAN_interface.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c miwa.c -o miwa.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c mvt.f -o mvt.o
mvt.f:861:11:

  861 |       hs = sign( one, dh - r*dk )
      |           1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:862:11:

  862 |       ks = sign( one, dk - r*dh )
      |           1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:1155:16:

 1155 |             K = MOD( C(NP, MIN(NDIM-1,KLIM-1))*DBLE(K), DBLE(P(NP)) )
      |                1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:1215:17:

 1215 |             JP = 1 + J*R(J)
      |                 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:94:39:

   94 |       DOUBLE PRECISION COV(NL*(NL+1)/2), A(NL), B(NL), DL(NL), Y(NL)
      |                                       1
Warning: Array ‘cov’ at (1) is larger than limit set by ‘-fmax-stack-var-size=’, moved from stack to static storage. This makes the procedure unsafe when called recursively, or concurrently from multiple threads. Consider using ‘-frecursive’, or increase the ‘-fmax-stack-var-size=’ limit, or change the code to use an ALLOCATABLE array. [-Wsurprising]
mvt.f:86:33:

   86 |       SUBROUTINE MVSUBR( N, W, NF, F )
      |                                 1
Warning: Unused dummy argument ‘nf’ at (1) [-Wunused-dummy-argument]
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c mvtnorm-init.c -o mvtnorm-init.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c tvpack.f -o tvpack.o
tvpack.f:395:14:

  395 |          HS = SIGN( ONE, DH - R*DK )
      |              1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
tvpack.f:396:14:

  396 |          KS = SIGN( ONE, DK - R*DH )
      |              1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
tvpack.f:60:52:

   60 |       DOUBLE PRECISION ONE, ZRO, EPS, ZROS(3), HS(3), TVT, TVTL
      |                                                    1
Warning: Unused variable ‘hs’ declared at (1) [-Wunused-variable]
tvpack.f:60:45:

   60 |       DOUBLE PRECISION ONE, ZRO, EPS, ZROS(3), HS(3), TVT, TVTL
      |                                             1
Warning: Unused variable ‘zros’ declared at (1) [-Wunused-variable]
tvpack.f:220:72:

  220 |       END
      |                                                                        ^
Warning: ‘fin’ may be used uninitialized in this function [-Wmaybe-uninitialized]
tvpack.f:196:58:

  196 |       DOUBLE PRECISION EI(NL), AI(NL), BI(NL), FI(NL), FIN, ERR, KRNRDT
      |                                                          ^
note: ‘fin’ was declared here
clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o mvtnorm.so C_FORTRAN_interface.o miwa.o mvt.o mvtnorm-init.o tvpack.o -L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: could not create compact unwind for _mvkrsv_: register 75 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvkbrv_: stack size is too large for frameless function
ld: warning: could not create compact unwind for _mvstdt_: register 75 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvbvtl_: registers 78 and 79 not saved contiguously in frame
ld: warning: could not create compact unwind for _pntgnd_: registers 72 and 73 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvu_: registers 72 and 73 not saved contiguously in frame
ld: warning: could not create compact unwind for _tvtmfn_: register 73 saved somewhere other than in frame
ld: warning: could not create compact unwind for _krnrdt_: registers 74 and 75 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvn_: registers 21 and 22 not saved contiguously in frame
ld: warning: could not create compact unwind for _bvnd_: registers 78 and 79 not saved contiguously in frame
ld: warning: could not create compact unwind for _bvtl_: registers 78 and 79 not saved contiguously in frame
ld: warning: could not create compact unwind for _tvtlrcall_: registers 72 and 73 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvt_: registers 21 and 22 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvspcl_: register 73 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvsort_: register 77 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvvlsb_: registers 27 and 28 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvtdst_: registers 23 and 24 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvtc_: register 73 saved somewhere other than in frame
installing to /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/00LOCK-mvtnorm/00new/mvtnorm/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (mvtnorm)

The downloaded source packages are in
    ‘/private/var/folders/fx/f46lfqf56_df59fvzgqhcbyr0000gn/T/RtmptXzvKK/downloaded_packages’
Gonsalves answered 20/10, 2021 at 3:15 Comment(3)
This worked for me (thanks!), but had to go into Mac security settings (twice) to approve fortran running.Publican
This does not work for me. I did all the permission change and security approvals. I think it is because the wheel searches for the gfotran executable file not the folder.Oestrin
Thanks, this led me to try to simply reinstall gcc: brew reinstall gcc, which solved my problem.Vegetarian
B
31

Here is what has worked for me on a Mac OS M1 system. R version 4.2.1 (modified from the solution here which will probably work for Intel Macs)

  1. Install gcc which includes gfortran with brew install gcc

  2. Create a file ~/.R/Makevars (if it does not exist yet). See for example here.

  3. Add the following lines to ~/.R/Makevars

FC = /opt/homebrew/Cellar/gcc/11.3.0_2/bin/gfortran
F77 = /opt/homebrew/Cellar/gcc/11.3.0_2/bin/gfortran
FLIBS = -L/opt/homebrew/Cellar/gcc/11.3.0_2/lib/gcc/11

Note that you might have to change gcc version 11.3.0_2 to whatever your gcc version is.

Building answered 15/7, 2022 at 17:47 Comment(6)
FLIBS = -L/opt/homebrew/Cellar/gcc/VERSION/lib removed the compilation warnings for me.Huygens
I confirm that this resolved the issue. Indeed make sure the paths are correct (by adjusting the version numbers).Chivalrous
Thank you! Solved my issue with mvtnorm installationVerditer
Thanks. Solved the problem with fastICA installationJelle
Thank you. Solved my problem with fastText.Papagena
Thanks. My path for homebrew cellar is: /usr/local/Cellar/Cottony
G
9

I deleted everything gfortran related and started over.

I downloaded the .tar.xz file here using the browser, which dumped the file into my Downloads folder. I double-clicked it to unpack it.

I moved that directory to where R wanted it:

markwhite@marks-air ~ % sudo mv Downloads/gfortran /opt/R/arm64/

Then I restarted R and tried again. It threw me some Fortran compilation messages—which I will not pretend to comprehend here—but it successfully installed:

> install.packages("mvtnorm")

  There is a binary version available but the source version is later:
        binary source needs_compilation
mvtnorm  1.1-2  1.1-3              TRUE

Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
installing the source package ‘mvtnorm’

trying URL 'https://cran.rstudio.com/src/contrib/mvtnorm_1.1-3.tar.gz'
Content type 'application/x-gzip' length 166421 bytes (162 KB)
==================================================
downloaded 162 KB

* installing *source* package ‘mvtnorm’ ...
** package ‘mvtnorm’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c C_FORTRAN_interface.c -o C_FORTRAN_interface.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c miwa.c -o miwa.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c mvt.f -o mvt.o
mvt.f:861:11:

  861 |       hs = sign( one, dh - r*dk )
      |           1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:862:11:

  862 |       ks = sign( one, dk - r*dh )
      |           1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:1155:16:

 1155 |             K = MOD( C(NP, MIN(NDIM-1,KLIM-1))*DBLE(K), DBLE(P(NP)) )
      |                1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:1215:17:

 1215 |             JP = 1 + J*R(J)
      |                 1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
mvt.f:94:39:

   94 |       DOUBLE PRECISION COV(NL*(NL+1)/2), A(NL), B(NL), DL(NL), Y(NL)
      |                                       1
Warning: Array ‘cov’ at (1) is larger than limit set by ‘-fmax-stack-var-size=’, moved from stack to static storage. This makes the procedure unsafe when called recursively, or concurrently from multiple threads. Consider using ‘-frecursive’, or increase the ‘-fmax-stack-var-size=’ limit, or change the code to use an ALLOCATABLE array. [-Wsurprising]
mvt.f:86:33:

   86 |       SUBROUTINE MVSUBR( N, W, NF, F )
      |                                 1
Warning: Unused dummy argument ‘nf’ at (1) [-Wunused-dummy-argument]
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c mvtnorm-init.c -o mvtnorm-init.o
/opt/R/arm64/bin/gfortran -mtune=native -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c tvpack.f -o tvpack.o
tvpack.f:395:14:

  395 |          HS = SIGN( ONE, DH - R*DK )
      |              1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
tvpack.f:396:14:

  396 |          KS = SIGN( ONE, DK - R*DH )
      |              1
Warning: Possible change of value in conversion from REAL(8) to INTEGER(4) at (1) [-Wconversion]
tvpack.f:60:52:

   60 |       DOUBLE PRECISION ONE, ZRO, EPS, ZROS(3), HS(3), TVT, TVTL
      |                                                    1
Warning: Unused variable ‘hs’ declared at (1) [-Wunused-variable]
tvpack.f:60:45:

   60 |       DOUBLE PRECISION ONE, ZRO, EPS, ZROS(3), HS(3), TVT, TVTL
      |                                             1
Warning: Unused variable ‘zros’ declared at (1) [-Wunused-variable]
tvpack.f:220:72:

  220 |       END
      |                                                                        ^
Warning: ‘fin’ may be used uninitialized in this function [-Wmaybe-uninitialized]
tvpack.f:196:58:

  196 |       DOUBLE PRECISION EI(NL), AI(NL), BI(NL), FI(NL), FIN, ERR, KRNRDT
      |                                                          ^
note: ‘fin’ was declared here
clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o mvtnorm.so C_FORTRAN_interface.o miwa.o mvt.o mvtnorm-init.o tvpack.o -L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: could not create compact unwind for _mvkrsv_: register 75 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvkbrv_: stack size is too large for frameless function
ld: warning: could not create compact unwind for _mvstdt_: register 75 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvbvtl_: registers 78 and 79 not saved contiguously in frame
ld: warning: could not create compact unwind for _pntgnd_: registers 72 and 73 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvu_: registers 72 and 73 not saved contiguously in frame
ld: warning: could not create compact unwind for _tvtmfn_: register 73 saved somewhere other than in frame
ld: warning: could not create compact unwind for _krnrdt_: registers 74 and 75 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvn_: registers 21 and 22 not saved contiguously in frame
ld: warning: could not create compact unwind for _bvnd_: registers 78 and 79 not saved contiguously in frame
ld: warning: could not create compact unwind for _bvtl_: registers 78 and 79 not saved contiguously in frame
ld: warning: could not create compact unwind for _tvtlrcall_: registers 72 and 73 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvt_: registers 21 and 22 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvspcl_: register 73 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvsort_: register 77 saved somewhere other than in frame
ld: warning: could not create compact unwind for _mvvlsb_: registers 27 and 28 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvtdst_: registers 23 and 24 not saved contiguously in frame
ld: warning: could not create compact unwind for _mvbvtc_: register 73 saved somewhere other than in frame
installing to /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/00LOCK-mvtnorm/00new/mvtnorm/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (mvtnorm)

The downloaded source packages are in
    ‘/private/var/folders/fx/f46lfqf56_df59fvzgqhcbyr0000gn/T/RtmptXzvKK/downloaded_packages’
Gonsalves answered 20/10, 2021 at 3:15 Comment(3)
This worked for me (thanks!), but had to go into Mac security settings (twice) to approve fortran running.Publican
This does not work for me. I did all the permission change and security approvals. I think it is because the wheel searches for the gfotran executable file not the folder.Oestrin
Thanks, this led me to try to simply reinstall gcc: brew reinstall gcc, which solved my problem.Vegetarian
G
5

I came across a similar problem when trying to install a package from source. My solution was

  1. Install the Homebrew version of gcc (this includes gfortran)

    brew install gcc

  2. Tell R where it should look for gfortran This information is stored in the file "Makeconf" which in my case can be found here: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/etc/Makeconf

In "Makeconf" change the line

FLIBS =  -L/Volumes/Builds/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/Volumes/Builds/opt/R/arm64/gfortran/lib/gcc -L/Volumes/Builds/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm

to

FLIBS =  -L/opt/homebrew/Cellar/gcc/11.3.0/lib/gcc/11/gcc/aarch64-apple-darwin21/11 -L/opt/homebrew/Cellar/gcc/11.3.0/lib/gcc/11 -lgfortran -lquadmath -lm

You may need to adapt the path according to the gcc version installed on your system.

  1. Restart R
Gasolier answered 11/5, 2022 at 11:20 Comment(0)
V
3

Have you tried to answer "no" to the question:

Do you want to install from sources the package which needs compilation? (Yes/no/cancel)

?

Except if you really need the latest version of the package you are trying to download, it seems to be working without having to install gfortran in the specified folder like you did.

Vannavannatta answered 18/11, 2021 at 22:50 Comment(0)
V
3

I have met the similar problem when installing other packages but I tried to do the following choice and it allowed me to go on:

Update all/some/none? [a/s/n]: 
n
Venerate answered 1/5, 2022 at 2:16 Comment(0)
F
2

I followed the instruction in this tutorial, and it worked: https://www.cynkra.com/blog/2021-03-16-gfortran-macos/

I created a file ~/.R/Makevars

and following the tutorial, type the following lines (using my own gfortran directory):

FC      = /usr/local/bin/gfortran
F77     = /usr/local/bin/gfortran
FLIBS   = -L/usr/local/bin/gfortran/lib
Farias answered 15/2, 2023 at 15:53 Comment(0)
D
1

The fix using a Makevars file (as suggested in the SO post that the error message in R links to) did not work for me, but modifying one of the other answers here (https://mcmap.net/q/650018/-installing-gfortran-on-macbook-with-apple-m1-chip-for-use-in-r) worked.

For context: I'm using a MacBook Pro 2023 M2 Max, macOS Ventura 13.5.2, R 4.3.1, gfortran installed with homebrew and Xcode installed.

  1. Just in case, make a backup of your Makeconf, like Makeconf.bak
  2. Open Makeconf in your editor of choice
  3. You probably see a lot of stuff. Further down, below the C and C++ sections, you should find the Fortran section, it might look like this:
## Fortran
FC = /opt/gfortran/bin/gfortran -arch arm64
FCFLAGS = -Wall -g -O2 $(LTO_FC)
## additional libs needed when linking with $(FC), e.g. on some Oracle compilers
FCLIBS_XTRA = 
FFLAGS = -Wall -g -O2 $(LTO_FC)
FLIBS =  -L/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0 -L/opt/gfortran/lib -lgfortran -lemutls_w -lquadmath
FPICFLAGS = -fPIC
FPIEFLAGS = -fPIE
F_VISIBILITY = 
  1. You need to change two lines here, for FC and FLIBS, as follows:
  2. For FC: Find out where gfortran is accessible from the terminal by running which gfortran
  3. For FLIBS: Run brew info gfortran to find out which version of gfortran is installed and to find the location you need to put in front of the version to complete the correct path
  4. In the Makeconf, edit the lines for FC and FLIBS with this information

For comparison, this is what the two lines in the Makeconf now look like for me:

FC = /opt/homebrew/bin/gfortran -arch arm64
FLIBS =  -L/opt/homebrew/Cellar/gcc/13.2.0/lib/gcc/13 -L/opt/homebrew/lib -lgfortran -lemutls_w -lquadmath

I hope this sheds some further light on this issue and helps someone getting frustrated with the Makevars fix not working for them as well.

Drops answered 12/9, 2023 at 11:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.