'Unable to install R packages due to library not found

In any R package I try to install, I get the following error message:

ld: library not found for -lintl
collect2: error: ld returned 1 exit status
make: *** [utf8.so] Error 1

I'm not sure how to make this a reprex, but I am running: R version 4.0.2 (2020-06-22) Platform: x86_64-apple-darwin19.5.0 (64-bit) Running under: macOS Catalina 10.15.5

What does this error message (ld: library not found for -lintl) mean and how can I fix it to be able to install R packages (the packages I have tried are texreg and lme4)? Thank you.

Edit: I apologize, I thought I had included this with my post. I am not missing gettext (as per Link error installing Rcpp "library not found for -lintl"), and I followed the instructions to export the LPDFLAGS and CPPFLAGS so that they are linked.

As best I can tell, the problem is the ~/.R/Makevars file, which currently looks like this, where I've commented out things I've added to it based on googling.

CC=/usr/local/Cellar/gcc/9.3.0_1/bin/gcc-9
CXX=/usr/local/Cellar/gcc/9.3.0_1/bin/g++-9
CXX11=/usr/local/Cellar/gcc/9.3.0_1/bin/g++-9
CXX14=/usr/local/Cellar/gcc/9.3.0_1/bin/g++-9
cxx17=/usr/local/cellar/gcc/9.3.0_1/bin/g++-9
cxx1X=/usr/local/cellar/gcc/9.3.0_1/bin/g++-9
LDFLAGS=-L/usr/local/Cellar/gcc/9.3.0_1/lib
#FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0

#CC=/usr/local/clang4/bin/clang
#CXX=/usr/local/clang4/bin/clang++
#CXX1X=/usr/local/clang4/bin/clang++
#CXX98=/usr/local/clang4/bin/clang++
#CXX11=/usr/local/clang4/bin/clang++
#CXX14=/usr/local/clang4/bin/clang++
#CXX17=/usr/local/clang4/bin/clang++
#LDFLAGS=-L/usr/local/clang4/lib


Solution 1:[1]

Apparently, I needed to remove all the lines from ~/.R/Makevars and I was able to install lme4. I did get some warnings, but library(lme4) works.

Solution 2:[2]

If you're using a mac with an Apple Silicon chip (like the M1), then you can try adding this to ~/.R/Makevars:

CFLAGS=-I/opt/homebrew/include
CPPFLAGS=-I/opt/homebrew/include
CXXFLAGS=-I/opt/homebrew/include
CXX11FLAGS=-I/opt/homebrew/include
LDFLAGS=-L/opt/homebrew/lib

This allows R to find the needed libraries. You will need to first ensure you have the needed compilers and dependencies installed. You can usually do this with brew.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lisa
Solution 2 Giovanni Colitti