J Li
J Li

Reputation: 121

Cannot load R package gmm on newest macbook with Apple M1 chip

I'm trying to load package gmm (running "library(gmm)") and get this error message below.

It seems unfixable, as it states that my gfortran/lib/libgomp.1.dylib has the wrong architecture? I'm guessing this is related to the new Mac architecture?

library(gmm) Loading required package: sandwich

Error: package or namespace load failed for ‘gmm’ in dyn.load(file, DLLpath = DLLpath, ...):

unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/gmm/libs/gmm.so':

dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/gmm/libs/gmm.so, 6): Library not loaded: /usr/local/gfortran/lib/libgomp.1.dylib Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/gmm/libs/gmm.so

Reason: no suitable image found. Did find:

**/usr/local/gfortran/lib/libgomp.1.dylib: mach-o, but wrong architecture**
/usr/local/gfortran/lib/libgomp.1.dylib: mach-o, but wrong architecture

Upvotes: 2

Views: 1645

Answers (2)

ehickman0817
ehickman0817

Reputation: 1

I encountered a similar issue after switching to a new Macbook Pro with the Apple M2 Max chip. The error that I got was:

Error: package or namespace load failed for ‘gmm’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/gmm/libs/gmm.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/gmm/libs/gmm.so, 0x0006): Library not loaded: /opt/R/arm64/gfortran/lib/libgomp.1.dylib
  Referenced from: <47242657-5A5D-3982-936B-398527D642B4> /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/gmm/libs/gmm.so
  Reason: tried: '/opt/R/arm64/gfortran/lib/libgomp.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/R/arm64/gfortran/lib/libgomp.1.dylib' (no such file), '/opt/R/arm64/gfortran/lib/libgomp.1.dylib' (no such file), '/usr/local/lib/libgomp.1.dylib' (no such file), '/usr/lib/libgomp.1.dylib' (no such file, not in dyld cache)

I tried the solution linked above as far as installing gfortran and restarting R, but that did not work. Here was the solution that did work (after installing gfortran):

  1. Locate the libgomp.1.dylib file by navigating to the terminal tab in RStudio and typing mfind libgomp.1.dylib. This will return the current location of the file.
  2. In Finder, go to the directory where the file is located (Go -> Go to Folder -> [paste directory]).
  3. In a new Finder window, go to the directory where R is looking for the file. I was able to navigate to the /opt/R/arm64/ folder, but the subfolders gfortran and lib did not exist, so I created them. I had to enter my computer password for each change to this folder.
  4. Copy the libgomp.1.dylib file from the first finder window to the new created folder. The file directory should match what R is looking for in the error message. So for me, it was /opt/R/arm64/gfortran/lib/libgomp.1.dylib.
  5. Uninstall the gmm package and/or the packages you were trying to install for which it is a dependency. Reinstall the packages and load them. They should install and load properly this time. I had an issue with a few dependencies not installing for my current version of R, and I worked around that by installing them using BiocManager.

Hope this is helpful to someone out there with the same errors!

Upvotes: 0

Camrin Braun
Camrin Braun

Reputation: 71

I had the same issue on R version 4.1. Found a similar question here which points to installing (or updating) your gfortran installation here. Once I did that and restarted R, the gmm package was able to find the missing image(s) automatically when I loaded the package.

Upvotes: 1

Related Questions