Compilation error (rstan)

Hi,

I am trying to use rstan for bayesian inference in a modeling study in public health. I stored the model definition in a character string in R, and called stan() function, as below:

fit1 <- stan(model_code = s, data = d_list)

However, an error occurred with details at the end this post. I actually tried the Eight schools example, and got exactly the same error message. I don’t have a background in computer science, and am quite confused with this problem. I will greatly appreciate it if someone can help.

Thanks a lot in advance!
Jianjiu

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! clang: warning: no such sysroot directory: ‘/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk’ [-Wmissing-sysroot]
In file included from file2f55c94c67a.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/StanHeaders/in
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file2f55c94c67a.cpp 2> file2f55c94c67a.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

Most likely something from below will work.

Thank you so much!

In my case, I tried 1, which did not work. I am not sure how to do 2-4; but after I tried 5, the compilation worked, and results were produced.

Best wishes
Jianjiu