Compiling error for 8schools example, MacOS Mojative

#1

Hi all,

This is my first time using Rstan, I followed the instruction from https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started to install it. When I try to compile the 8schools example in Rstudio, it returns an error which shows below:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from file146ec754c9e8c.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/memory/stack_alloc.hpp:8:
In file included from /usr/local/clang4/bin/…/include/c++/v1/cstdlib:86:
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file146ec754c9e8c.cpp 2> file146ec754c9e8c.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

Can anyone help me with that?

R version: 3.5.3
Rstuido version: 1.2.1330
Rstan version: 2.18.2

Thanks in advance!

Yize

0 Likes

#2

What is the string surrounding the word error: (with the colon) when doing

stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}'
mod <- stan_model(model_code = stancode, verbose = TRUE)
0 Likes

#3

Hi bgoodri,

Do you mean this part? (shown below)

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from file146ec27adb17c.cpp:8:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/src/stan/model/model_header.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/rev/core/autodiffstackstorage.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/3.5/Resources/library/StanHeaders/include/stan/math/memory/stack_alloc.hpp:8:
In file included from /usr/local/clang4/bin/…/include/c++/v1/cstdlib:86:

0 Likes

#4

No, I mean the part that starts with error:. It probably then says something to the effect of “cannot find this file”.

0 Likes

#5

In file included from /usr/local/clang4/bin/…/include/c++/v1/cstdlib:86:
/usr/local/clang4/bin/…/include/c++/v1/stdlib.h:94:15: fatal error: ‘stdlib.h’ file not found
#include_next <stdlib.h>
^~~~~~~~~~
1 error generated.
make: *** [file146ec4012a52f.o] Error 1

ERROR(s) during compilation: source code errors or compiler configuration errors!

I think this might be what you look for?

0 Likes

#6

It stated that ‘stdlib.h’ file not found.

0 Likes

#7

Then this applies

0 Likes

#8

If that doesn’t work but you have a /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14. pkg , install that so it puts C++ headers back in /usr/include

For this one do you mean I need to type this code into R or Xcode?

0 Likes

#9

It just means you need to click on /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14. pkg from Finder.

0 Likes

#10

Sorry I’m still not clear about this stuff.

1. Make sure you have opened Xcode once via Spotlight to accept its license

I have open Xcode but I don’t need to do something else except open this app, do I?

2. If that doesn’t work but you have a /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14. pkg , install that so it puts C++ headers back in /usr/include

For this one I don’t have a finder called ‘Packages’ in CommandLineTools. So where can I download the relevant package?

3. If that doesn’t work, rename / delete / empty the ~/.R/Makevars file to use Xcode’s clang++ rather than LLVM’s

Similarly, how can I do this step?

4. If that doesn’t work, recreate ~/.R/Makevars with a line that says CXX14FLAGS = -isystem ??? where ??? means the path to the C++ header files such as /usr/include

And what about this?

Sorry for lots of questions regarding these. I’m also a stranger to MacOS system so I’m really confused about these stuff.

0 Likes

#11

For 2, if you do in R

dir(file.path("Library", "Developer", "CommandLineTools", "Packages"))

what does it say?

0 Likes

#12

Sorry for the late reply. It will return: character(0)

0 Likes

#13

OK, try in R doing

file.rename(from = "~/.R/Makevars", to = "~/.R/Makevars_old")

and then try to compile something again.

0 Likes

#14

It still does not work.

file.rename(from = “~/.R/Makevars”, to = “~/.R/Makevars_old”)
[1] FALSE
Warning message:
In file.rename(from = “~/.R/Makevars”, to = “~/.R/Makevars_old”) :
cannot rename file ‘/Users/mayize/.R/Makevars’ to ‘/Users/mayize/.R/Makevars_old’, reason ‘Permission denied’

0 Likes

#15

That is atypical. Try

Sys.setenv(R_MAKEVARS_USER = "/dev/null")

and then compiling something.

0 Likes

#16

Thank you so much for your patience! It works now!

0 Likes

#17

OK, that is only temporary. Outside of R / RStudio, you need to find a way to delete the file at /Users/mayize/.R/Makevars.

0 Likes

#18

But I cannot find this /Users/mayize/.R/Makevars file in my laptop. Actually there is no “.R” folder in /Users/mayize.

0 Likes

#19

You may have to enable seeing “hidden” folders (those that start with a dot).

0 Likes

#20

Wow thanks a lot! I figured it out.

0 Likes