stan-dev / stan-dev/rstan

M1 mac, cannot install binary, c++ exception (unknown reason) when using source install

Open
#947 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

Summary:

rstan, which was working 3 weeks ago, suddenly stopped providing informative error messages, instead giving c++ exception (unknown reason). Attempting to reinstall fails with various errors depending on the installation method.

Description:
  1. The initial error causing my problem was that I have suddenly started getting c++ exception (unknown reason) on any error when trying to run a stan model. Following the advice I found from searching around, e.g., here, I tried to reinstall rstan from source:

install.packages("rstan", type = "source")

This seemingly successfully compiles, but fails at the end when it tries to load the package:

Error: package or namespace load failed for ‘rstan’:
 .onLoad failed in loadNamespace() for 'rstan', details:
  call: dyn.load(tbbmalloc_proxy, local = FALSE, now = TRUE)
  error: unable to load shared object '/private/var/folders/6w/y9r4gl_x4hs80gtsj4k7ynbh0000gn/T/Rtmp8BXbOH/R.INSTALL1128151514a75/rstan/':
  dlopen(/private/var/folders/6w/y9r4gl_x4hs80gtsj4k7ynbh0000gn/T/Rtmp8BXbOH/R.INSTALL1128151514a75/rstan/, 10): no suitable image found.  Did find:
	/private/var/folders/6w/y9r4gl_x4hs80gtsj4k7ynbh0000gn/T/Rtmp8BXbOH/R.INSTALL1128151514a75/rstan/: not a file
	/private/var/folders/6w/y9r4gl_x4hs80gtsj4k7ynbh0000gn/T/Rtmp8BXbOH/R.INSTALL1128151514a75/rstan: not a file
Error: loading failed
Execution halted

I tried editing CXX in ~/.R/Makevars to try different compilers (I have g++, apple clang, and macports clang), but this did not change the compiler messages (i.e., it still compiles with clang even when I change CXX to g++).

  1. Next I tried to clone the GitHub repository, run make build, then use R CMD INSTALL to install the package. This succeeds. However, running a test model with a syntax error again gives me c++ exception (unknown reason).

  2. Finally, I tried to re-install the CRAN binary. The installation also succeeds (and is correctly getting the arm64 build). However, I cannot load the package:

> library("rstan")
Loading required package: StanHeaders
Loading required package: ggplot2
Error: package or namespace load failed for ‘rstan’:
 .onLoad failed in loadNamespace() for 'rstan', details:
  call: dyn.load(tbbmalloc_proxy, local = FALSE, now = TRUE)
  error: unable to load shared object '/Users/mtalluto/':
  dlopen(/Users/mtalluto/, 10): no suitable image found.  Did find:
	/Users/mtalluto/: not a file
	/Users/mtalluto: not a file

The directory indicated is my working directory!

Reproducible example

I can only run this after installing using method 2 above.

library(rstan)
code = "
data {
vector [5] x // syntax error, no ;
}
parameters {
real mu;
}
model {
x ~ normal(mu, 1)
}
"

stan_model(model_code = code)

## Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
##    c++ exception (unknown reason)
RStan Version:

2.21.3

R Version:

4.1.0 (2021-05-18)

Operating System:

macOS 11.4, arm64 version

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the macOS arm64 installation paths in the report, especially ~/.R/Makevars, make build, and R CMD INSTALL, then reproduce loading rstan and the stan_model syntax-error example. Done means the package installs and loads correctly from the relevant methods and the malformed model produces an informative diagnostic instead of a generic C++ exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, macos, r
Domain
build-system, compilers, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.