Skip to content
Prev 14872 / 15075 Next

R/compilers can't find libintl.h on MacOS X

Gavin,

there are few issues here with different possible solutions.

In general, you cannot mix R from Homebrew and CRAN - they use different toolchains and libraries so you have to pick one.


1) Despite what you said, what you are showing below is output from CRAN R, so one option (which I'd recommend) is to go the CRAN way. First, simply remove (or rename) /opt/homebrew so it doesn't break things (may or may not be necessary). Then the error you see is because mgcv seems to require gettext so install it from https://mac.r-project.org/bin/ - either follow the instructions there (which will work even from more complex cases) or in your case you can simply use

curl https://mac.r-project.org/bin/darwin20/arm64/gettext-0.22.5-darwin.20-arm64.tar.xz | tar xz -C /

(if you don't have write permissions in /opt/R either run "sudo chown -R $USER /opt/R" or put "sudo" before the tar above).

Once you got whatever you needed compiled you can rename /opt/homebrew back since we only need to remove it for compilation. The above works, because R itself already has the necessary static library built-in (as it uses it itself) so all you need are the gettext headers to appease mgcv.


2) If you want to go fully the Homebrew way then you have to make sure you are picking up R from Homebrew and not CRAN. Then you cannot use CRAN binaries, you are entirely on your own since we don't support that setup, so I do NOT recommend it, but it's possible. Typically, that requires you to install the full compiler toolchain from Homebrew as well as well compiling all R packages from sources. In that scenario you don't use anything from mac.R-project.org but instead rely fully on Homebrew. This includes OpenMP, because the compilers in Homebrew are not from Apple so they use their own OpenMP.


3) If the mgcv package on CRAN does not come with OpenMP support then I'd contact the maintainers and ask them why they don't enable it. Packages that benefit significantly from OpenMP typically enable it for their CRAN binaries (good example is data.table), so if it is not enabled it may mean that the authors don't recommend it or there is no significant benefit.


Cheers,
Simon