macOS RStan Installation Issues

I am attempting to install RStan by following these instructions.

I have installed the macOS R toolchain using the macOS R toolchain installer.

I have done the configurations for clang++ by running the following R code:

dotR <- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
MAKEVARS <- file.path(dotR, "Makevars")
if (!file.exists(MAKEVARS)) file.create(MAKEVARS)

cat(
  "\nCXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function  -Wno-macro-redefined -Wno-unknown-pragmas",
  "\nCC=clang",
  "CXX=clang++ -arch x86_64 -ftemplate-depth-256"
  file = MAKEVARS, 
  sep = "\n", 
  append = TRUE
)

# print the contents to the console 
cat(readLines(MAKEVARS), sep = "\n")

And then, as per the instructions, I then attempt to verify that the toolchain works by executing the code below in R and checking that it returns the value 10:

fx <- inline::cxxfunction( signature(x = "integer", y = "numeric" ) , '
	return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
                           ' )

fx( 2L, 5 ) # should be 10

However, I get the following error:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! ld: library not found for -lintl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [filee7df6bc649.so] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/usr/local/Cellar/r/3.5.0/lib/R/bin/R CMD SHLIB filee7df6bc649.cpp 2> filee7df6bc649.cpp.err.txt’ had status 1

I have a time-critical project that I am trying to complete, so I would greatly appreciate it if people could please take the time to help me fix this.

I think this issue is connected to another issue I was having, which I posted about on Github.

Someone / something else added -lintl to LDFLAGS, which is not needed for Stan and apparently you don’t have or don’t have configured correctly. What does

# print the contents to the console 
cat(readLines(MAKEVARS), sep = "\n")

actually say? It is possible that -lintl comes from one of the other Makefiles.

I’ve solved this issue, thanks to the gracious assistance of @bgoodri. Please see here for details.