-
Notifications
You must be signed in to change notification settings - Fork 303
Compilation on MacOS Monterey M1 (ARM64 architecture) #1848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is possibly solved here by @drkrynstrng : |
on the M1 I have been using it without homebrew. You need to install some of these libraries: https://mac.r-project.org/libs-arm64/ i'm late for a class ... i will try to reply you later with more information. Just wanted to give you some update. |
On my M1 I just had to install "gfortran" and "pkgconfig" here "/opt/R/arm64/bin". No homebrew was necessary. The packages in R compiles from the source normally after that. MacOS may ask you permissions, just open the files, right click on it, and terminal will allow permissions automatically. By the way, "to install" these libraries, just unzip the files and move the folders, keeping the same structure. The very first one you will only need to move the folders. If you need more libraries, keep the same file structure. Hope it helps. Let us know if any question. |
close? |
Now it compiles correctly on an M1 with Monterey even with a standard homebrew install of pkg-config, GDAL, PROJ and GEOS. |
Hi @aourednik. It seems as though you got sf to install from source with pkg-config, gdal, proj, and geos installed via homebrew on an M1 Mac. I have the same setup as you and am still getting the original error above (pkg-config not found). Were there additional steps you had to take? I did:
and get the same error above:
and the same error again after running this in R prior to the
I have no problem executing the pkg-config command in a bash terminal. For example, Thanks for any advice. MacOS Monterey 12.1 on M1 Pro (ARM64) |
OK, I think I figured it out. For whatever reason, R was not recognizing the PATH env variable updated in my .bash_profile to begin with
I did not need to add any configuration arguments for gdal or proj, as R found everything and both packages installed cleanly (although sf had 6 warnings which I have seen in the past on previous installs). Now sf links to the homebrew spatial libraries:
This same approach also worked for terra and stars. I am not sure if the PATH always needs to have My system is: |
Unfortunately, the problem is back with gdal 3.4 : sf is looking for the 2.9 version. As of 2022, Homebrew updates GDAL to 3.4 /opt/homebrew/Cellar/gdal/3.4.0/lib/libgdal.30.dylib , symlinked from /opt/homebrew/opt/gdal/ The effect on the sf library is immediate:
Trying to reinstall:
I've tried to install an older version of GDAL with homebrew, to no avail:
|
Please note that homebrew is the choice and complete responsibility of anyone choosing that path. M1 is supported with CRAN binaries, static linked to external software (usually not the latest version, but fairly new). You seem to be surprised that your sf installation ceased to load when the dynamically linked library against which it was built and installed is absent. It is unusual for ABI compatibility to extend over GDAL/PROJ/GEOS releases, so any local update to any of these upstream dependencies will require a source install of sf. The final problem you hit is that software required by PROJ is not found (PROJ needs libtiff, libsqlite3 and libcurl in places where they can be found by configure). So for convenience and less loss of time, use CRAN binaries only and never install spatial packages using external software from source (sf, lwgeom, terra, vapour, rgdal, rgeos, etc.). The only viable reason for source installs using non-CRAN dynamic linking is that newer versions offer functionality not present in CRAN static-linked binaries. You may of course install source packages using CRAN static-built libraries, but this is only relevant if you must have the development version of a package, but this should really only apply to those contributing to package development (you've made an edit to a local fork of sf and want to check its performance). |
Thanks for fast reply @rsbivand . Today I've noticed that my MacOS version of R, for a reason I believed necessary up to now, defaults to building from source when running install.packages("package-name") despite there being MacOS binaries available on CRAN. SF is a great package, I've become quite dependent to it in my processes, it's always a haunting experience when it stops working :-) |
just have a .Renviron file in your home folder with |
Thanks @abuabara, this could be a general workaround indeed. But for some cases, I need packages to compile, for instance data.table, that needs a special Makevars file with CC and CXX flags specifying the use of fopenmp. However, I've found a one-liner to solve all the sf installation issues above, forever :-) Run:
instead of @rsbivand : perhaps this could be noted somewhere in the installation section of the sf website ? I've also filed a feature proposal to RStudio to make this a default behaviour of package manager: rstudio/rstudio#10360 |
Thanks! See #1621 (comment) |
I just ran into this issue as well installing sf on a new M1 machine and I think I have any idea about the cause and a potential fix (for at least the original issue). With homebrew on these newer Macs everything is being installed into
which doesn't include However, this information is available in Line 441 in cc698f2
Line 467 in cc698f2
which then includes the necessary -L/opt/homebrew/lib and all of the libraries to be found allowing linking to succeed for these checks.
One non-package interim fix is that users can also add |
I think that only non-package resolutions are acceptable. The draft Spatial task view (private repo until new task views are rolled out) says:
It will be much more helpful if homebrew people (who have by definition some insight into build systems) rather help with migrating GEOS, PROJ and especially GDAL to static cmake for the static binaries. Incidentally, shall I open a PR to sf/README.md to remove homebrew completely, I don't think homebrew should be advocated so obviously when most homebrew issues actually suggest that the questioner should only be installing binary packages. Some work has been done by Simon U, Tomas K and especially BDR, but GDAL is very likely to be very difficult to resolve. Contributions to get Rtools42 and the macOS recipes ready for GDAL 3.5 (see also this thread: https://lists.osgeo.org/pipermail/gdal-dev/2022-January/055253.html) would be most valuable, as cmake implementations in these libraries are most likely happening because their downstream users (QGIS, PostGIS) want it, not because library developers know cmake. |
Under 'Steps', I believe this should be
And not
(Note the dot before, not after the 'R'.) |
@abuabara, using the binaries at https://mac.r-project.org/bin/darwin20/arm64/ how did you install them? |
I think https://mac.r-project.org/bin/ is where to start, you'll need the support files and headers too. I can check Thursday afternoon CET. |
I'll update my version of R and try from scratch and do my best to document it. |
Installed a fresh R version 4.2.2. CRAN binaries have been installed but are not picked up by {sf} when installing. There is no other gdal installation. which gdal
gdal not found In terminal sudo R
source("https://mac.R-project.org/bin/install.R")
install.libs("gdal")
Downloading https://mac.R-project.org/bin/REPOS ...
Using repository https://mac.R-project.org/bin/darwin20/arm64 ...
Downloading index https://mac.R-project.org/bin/darwin20/arm64/PACKAGES ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/gdal-3.5.3-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/pkgconfig-0.29.2-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/xz-5.2.6-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/libpq-14.5-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/proj-9.1.0-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/openjpeg-2.5.0-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/libwebp-1.2.4-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/libgeotiff-1.7.1-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/freexl-1.0.6-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/sqlite3-3.39.3-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/expat-2.4.8-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/hdf4-4.2.15-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/hdf5-1.12.2-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/szip-2.1.1-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/netcdf-4.8.1-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/geos-3.11.0-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/unixodbc-2.3.11-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/zlib-stub-0.1-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/tiff-4.4.0-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/libpng-1.6.38-darwin.20-arm64.tar.xz ...
Downloading + installing https://mac.R-project.org/bin/darwin20/arm64/jpeg-9e-darwin.20-arm64.tar.xz ...
quit()
ls /opt/R/arm64/bin | grep "gdal"
gdal-config
gdal_contour
gdal_create
gdal_grid
gdal_rasterize
gdal_translate
gdal_viewshed
gdaladdo
gdalbuildvrt
gdaldem
gdalenhance
gdalinfo
gdallocationinfo
gdalmanage
gdalmdiminfo
gdalmdimtranslate
gdalsrsinfo
gdaltindex
gdaltransform
gdalwarp Open fresh RStudio session:
|
is |
I added I was able to get
This uses only CRAN binaries. |
|
Ah |
Compiling from source under MacOS Monterey 12.0.1 on M1 (ARM64) fails.
R version 4.1.2 (2021-11-01)
Platform: aarch64-apple-darwin20.6.0 (64-bit)
Steps :
homebrew install
install.packages("sf")
: Fails with error "gdal-config not found or not executable"install.packages("sf",configure.args = "--with-gdal-config=/opt/homebrew/opt/gdal/bin/gdal-config")
: Solves the gdal-problem, but also fails with this trace:The text was updated successfully, but these errors were encountered: