# Cmdstanr gets stuck in compilation

**URL:** <https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173>\
**Category:** Interfaces\
**Tags:** cmdstanr\
**Created:** [April 8, 2020, 2:59am UTC](https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173 "2020-04-08T02:59:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![stijn](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stijn/32/105_2.png) [@stijn](https://discourse.mc-stan.org/u/stijn)\
**Post date:** [April 8, 2020, 2:59am UTC](https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173/1 "2020-04-08T02:59:53Z")

</div>

Operating System: Catalina  
Interface Version: cmdstanr 0.0.9000, stanc v2.22.1(unix)  
Compiler/Toolkit: macos-rtools

I got the problem that cmdstanr gets stuck when compiling a stan model or even installing cmdstan.

I starting using cmdstan awhile ago. Last week, I installed the macos-rtools to get rstanarm and brms working again on Catalina. All went well as far as I could see. However, when I tried to use cmdstanr again I got errors that made me think that because I switched compilers I had to recompile cmdstan. That did not finish after \>12hours. I then recompiled cmdstan from the command line and it was a breeze (5 minutes).

The problem now is that cmdstanr is taking ages (killed it after 10 minutes) to compile simple models. Again from the command line, everything is fine. In fact, it’s so fast that I thought nothing has happened at first (kudos on that!).

* * *

As a side note: the bernoulli example in cmdstan throws an error.

```
Semantic error in 'examples/bernoulli/bernoulli.stan', line 10, column 6 to column 15:
   -------------------------------------------------
     8: model {
     9: theta ~ beta(1,1); // uniform prior on interval 0,1
    10: y ~ bernoulli(theta);
               ^
    11: }
   -------------------------------------------------

Identifier 'bernoulli' clashes with model name.

```

* * *

Current `~/.R/makevars`

```
# clang: start
CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include

SHLIB_CXXLDFLAGS+=-Wl,-rpath,${R_HOME}/lib ${R_HOME}/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,${R_HOME}/lib ${R_HOME}/lib/libc++abi.1.dylib
# clang: end

```

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [April 8, 2020, 7:38am UTC](https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173/2 "2020-04-08T07:38:14Z")

</div>

I am not an expert on anything Mac related but @andrewgelman had a similar issue installing on Catalina.

@mitzimorris got to the bottom of this and found out that Catalina has added a bunch of security features such that the stanc binaries when downloaded are automatically quarantined (sign of the times :) ) because they are not signed using Apple developer program credentials.

This issue was fixed on the cmdstan side but is currently only available on the Github repository. You need to install cmdstan from the repo using  
`install_cmdstan(repo_clone = TRUE, cores = 4)`

> [@stijn](#):
>
> As a side note: the bernoulli example in cmdstan throws an error.

Hm, I am confused by this one. We did change the compilation of models so that we now explicitly set the name stanc flag so it could come from that. But I am unable to reproduce this one :/

```
library(cmdstanr)

file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)

```

This runs ok for me.

Can you make sure you are using the latest version of cmdstanr. Sorry for the troubles.

---

<div class="post-metadata">

**Author:** ![stijn](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stijn/32/105_2.png) [@stijn](https://discourse.mc-stan.org/u/stijn)\
**Post date:** [April 8, 2020, 8:44am UTC](https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173/3 "2020-04-08T08:44:25Z")

</div>

> [@rok\_cesnovar](#):
>
> install\_cmdstan(repo\_clone = TRUE, cores = 4)

Thanks, Rok. Unfortunately that did not work for me. I got a lot of clang++ messages like these

```no-highlight
clang++ -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.3 -I stan/lib/stan_math/lib/boost_1.72.0 -I stan/lib/stan_math/lib/sundials_5.2.0/include -DBOOST_DISABLE_ASSERTS -c -MT bin/cmdstan/lang/grammars/bare_type_grammar_inst.o -MT stan/src/stan/lang/grammars/bare_type_grammar_inst.d -MM -E -MG -MP -MF stan/src/stan/lang/grammars/bare_type_grammar_inst.d stan/src/stan/lang/grammars/bare_type_grammar_inst.cpp

```

and then cmdstan\_install times out. The command line building worked fine again. `cmdstan_model` just hangs again.

> [@rok\_cesnovar](#):
>
> Can you make sure you are using the latest version of cmdstanr. Sorry for the troubles.

I reinstalled cmdstanr from github. No worries about the troubles. I know cmdstanr is still beta and Catalina has been something else. I can work with `rstan` for the moment. I am going to miss those sweet compile times though :-).

* * *

sidenote:

```no-highlight
bin/stanc --name=bernoulli examples/bernoulli/bernoulli.stan

```

throws the error I mentioned before. I used that because that is what the cmdstan starting guide suggests. The following two calls work without a hitch.

```no-highlight
bin/stanc examples/bernoulli/bernoulli.stan
bin/stanc --name=bernoulli2 examples/bernoulli/bernoulli.stan

```

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [April 8, 2020, 9:57am UTC](https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173/4 "2020-04-08T09:57:10Z")

</div>

```no-highlight
bin/stanc --name=bernoulli examples/bernoulli/bernoulli.stan

```

That needs to be fixed ASAP as it wont work with cmdstan 2.21+. Didnt realize that was an example somewhere. Thanks. EDIT: Fix in process [Bugfix/Issue #848 Fix the stanc example in cmdstan guide by rok-cesnovar · Pull Request #849 · stan-dev/cmdstan · GitHub](https://github.com/stan-dev/cmdstan/pull/849)

> [@stijn](#):
>
> and then cmdstan\_install times out.

Yeah, this has something to do with clang and Catalina. I am sorry, cant help much there as I am complete noob when it comes to Macs. Hopefully @mitzimorris has an idea.

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [April 8, 2020, 2:03pm UTC](https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173/5 "2020-04-08T14:03:23Z")

</div>

> [@stijn](#):
>
> The following two calls work without a hitch.
> 
> ```no-highlight
> bin/stanc examples/bernoulli/bernoulli.stan
> bin/stanc --name=bernoulli2 examples/bernoulli/bernoulli.stan
> 
> ```

we should definitely go with the first example - get rid of the `--name` arg in both the example and the makefile.

maybe the stanc3 compiler changed something, if so, wondering why this didn’t get noticed sooner. investigating.

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [April 8, 2020, 2:23pm UTC](https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173/6 "2020-04-08T14:23:36Z")

</div>

Yes, stanc3 requires the model name not to be used. The default name is usually filename\_model so its not really an issue.  
I will delete the use of name from the example on the PR.

Not sure what you mean by removing it from makefile? I think @stijn just played around directly with the stanc3 compiler binaries.

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [April 8, 2020, 4:08pm UTC](https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173/8 "2020-04-08T16:08:26Z")

</div>

Is this a Mac specific issue? I am not sure I completely understand what the issue is :/

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [April 8, 2020, 4:30pm UTC](https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173/9 "2020-04-08T16:30:25Z")

</div>

perhaps this is due to the `~/.Renviron` file? cf [CmdStanR - install\_cmdstan() not finishing build of cmdstan - #14 by rok\_cesnovar](https://discourse.mc-stan.org/t/cmdstanr-install-cmdstan-not-finishing-build-of-cmdstan/11929/14)

here’s the initial report:

> [@stijn](#):
>
> I starting using cmdstan awhile ago. Last week, I installed the macos-rtools to get rstanarm and brms working again on Catalina. All went well as far as I could see. However, when I tried to use cmdstanr again I got errors that made me think that because I switched compilers I had to recompile cmdstan.

---

<div class="post-metadata">

**Author:** ![stijn](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stijn/32/105_2.png) [@stijn](https://discourse.mc-stan.org/u/stijn)\
**Post date:** [April 9, 2020, 1:26am UTC](https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173/10 "2020-04-09T01:26:14Z")

</div>

Thanks Mitzi!

Removing ~/.Renviron did the trick. My apologies, I should have found that thread on my own. Back to the sweet compile times for me.

Stijn.

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [April 9, 2020, 1:47am UTC](https://discourse.mc-stan.org/t/cmdstanr-gets-stuck-in-compilation/14173/11 "2020-04-09T01:47:32Z")

</div>

no need to apologize - this is not something we expect people to know about.

thanks for confirming that this was the problem. @bgoodri and @jonah - this is a problem - file issue on RStan? or?
