Dealing with Catalina IV

If you are trying to install the pkg from

in order to get the C++ toolchain setup on Catalina, then to open it you apparently have to hold down Ctrl while clicking on the installer file that you downloaded. At that point it should look like

and clicking Open will get it going.

You probably need to have R 3.6 or later for things to work smoothly.

Also, you will probably have to install rstan and related packages from source, via

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

and similarly for rstanarm and other R packages that come with compiled Stan programs.

I am on macOS Catalina 10.15.3
and using R version 3.6.3 (2020-02-29)

I followed the instructions here, installing rtools and then running install.packages(c(ā€œStanHeadersā€, ā€œstanā€), type = ā€œsourceā€).

However, when I now try to install RStan (by calling install.packages(c(ā€œrstanā€), type = ā€œsourceā€)), I get the following error:

In file included from pointer-tools.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/random/additive_combine.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config.hpp:57:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config/platform/macos.hpp:28:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config/detail/posix_features.hpp:18:
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:655:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/gethostuuid.h:39:17: error: C++ requires a type specifier for all declarations
int gethostuuid(uuid_t, const struct timespec *) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_NA);
                ^
In file included from pointer-tools.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/random/additive_combine.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config.hpp:57:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config/platform/macos.hpp:28:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config/detail/posix_features.hpp:18:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:662:27: error: unknown type name 'uuid_t'; did you mean 'uid_t'?
int      getsgroups_np(int *, uuid_t);
                              ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types/_uid_t.h:31:31: note: 'uid_t' declared here
typedef __darwin_uid_t        uid_t;
                              ^
In file included from pointer-tools.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/random/additive_combine.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config.hpp:57:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config/platform/macos.hpp:28:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config/detail/posix_features.hpp:18:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:664:27: error: unknown type name 'uuid_t'; did you mean 'uid_t'?
int      getwgroups_np(int *, uuid_t);
                              ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types/_uid_t.h:31:31: note: 'uid_t' declared here
typedef __darwin_uid_t        uid_t;
                              ^
In file included from pointer-tools.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/random/additive_combine.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config.hpp:57:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config/platform/macos.hpp:28:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config/detail/posix_features.hpp:18:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:727:31: error: unknown type name 'uuid_t'; did you mean 'uid_t'?
int      setsgroups_np(int, const uuid_t);
                                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types/_uid_t.h:31:31: note: 'uid_t' declared here
typedef __darwin_uid_t        uid_t;
                              ^
In file included from pointer-tools.cpp:2:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/random/additive_combine.hpp:22:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config.hpp:57:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config/platform/macos.hpp:28:
In file included from /Library/Frameworks/R.framework/Versions/3.6/Resources/library/BH/include/boost/config/detail/posix_features.hpp:18:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:729:31: error: unknown type name 'uuid_t'; did you mean 'uid_t'?
int      setwgroups_np(int, const uuid_t);
                                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/_types/_uid_t.h:31:31: note: 'uid_t' declared here
typedef __darwin_uid_t        uid_t;
                              ^
5 errors generated.
make: *** [pointer-tools.o] Error 1
ERROR: compilation failed for package ā€˜rstan’

Any ideas for how to fix this? Seems like it might be related to this error

What is packageVersion("BH")?

Thanks for the quick response!
Here’s the output:

packageVersion(ā€œBHā€)
[1] ā€˜1.72.0.3’

I think the problem is the type uuid_t is not defined at anywhere. So the declaration at line 662 in the file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h will cause error for example.

In the first attempt, I tried to add one line into that unistd.h file:
#include <sys/_types/_uuid_t.h> at line 83. But it doesn’t help.

Because I don’t want to go deeper to edit many system file, I add another line into unistd.h to manually define the type of uuid_t, based on the definition in _uuid_t.h .
typedef __darwin_uuid_t uuid_t; at line 661, after ā€œ#endifā€.

Then it worked.

I am not sure if this is an error in the source code of MacOSX.10.15.sdk or not. But if you want to fix it in this way, please make sure you have the root permission when editing those files.

So this is a bug in the Xcode command line tools? is there a previous version that works for sure? I’d rather not edit these if possible

I’m getting weird behavior on Catalina when compiling any model that has an error. Instead of reporting the error, stan_model or stanc just returns with no error message, and no value returned. Thereafter no error messages nor warning messages of any sort are reported by any other command executed. Digging deeper I found that the FFI call within stanc fails, throwing an unknown C++ exception, and fails to properly restore stderr (which it had redirected to a file). I’ve filed this as issue #751 for standev/rstan.

Despite this, I can compile and run the 8schools example without problem, and likewise I can run prophet, which relies on RStan.

Yes, I carefully followed the instructions for installing RStan on MacOS Catalina using the ā€œmacOS R toolchain installerā€ linked to on the page ā€œInstalling RStan from source on a Macā€, and this was fairly recently, with the last few weeks.

Has anyone else encountered this problem? Does anyone know of a reasonable work-around? It’s difficult to debug a Stan model if you can’t get back any error messages from the compiler.

When stanc returns nothing that just means there was a syntax error but Catalina is causing the error message to get lost. If you install rstan from source via CRAN, it should resolve itself.

Thanks, that seems to solve it. It’s puzzling, though, because I DID originally install RStan from source via CRAN, just a few weeks ago, and it was the same version (2.19.3).

@bgoodri sorry to bother you again but just curious if there was any other suggestion to try besides going in and editing the command line tools as suggested by @Tan_Phan? Mac pushed out a command line tools update a couple of days ago but that didn’t seem to solve eh problem…

@coatless: Have you seen errors like the one @davidh is encountering that look like

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:727:31: error: unknown type name ā€˜uuid_t’; did you mean ā€˜uid_t’?

@bgoodri there is an issue with the current version of Rcpp v1.0.4 on CRAN.

In short, it’s now required to compile Rcpp from source at its drat repository

The following should be used until v1.0.5 or R 4.0.0 is released (on April 24th):

install.packages("Rcpp", repos="https://rcppcore.github.io/drat")
install.packages("rstan", type = "source")

Details on the Rcpp buglet:

Thanks @coatless! For anyone else with this issue, I had to first install Rcpp from

install.packages(ā€œRcppā€, repos = ā€œRcpp Dratā€)

and then install rstan

Can we add,

install.packages("Rcpp", repos="https://rcppcore.github.io/drat")

to the main rstan install instructions at,

and

until the bug is fixed?

Done

Hey,

I m experiencing the same issues ([1] "Error in sampler$call_sampler(args_list[[i]]) : ā€œ[2] " c++ exception (unknown reason)ā€ error occurred during calling the sampler; sampling not done)

I ve been trying to follow the steps outlined here:

  1. Downloaded toolchain - rmacoslib/r-macos-rtools
  2. install.packages(c(ā€œStanHeadersā€, ā€œrstanā€), type = ā€œsourceā€)```

I have seen posts elsewhere about suggesting replacing Makevars - i m not sure what that is and whether it is necessary given the thread above.

I have Catalina and the newest R version and R-studio.

Thanks

The r-macos-rtools should setup your C++ toolchain correctly (but it seems to not always succeed). If you try

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

the unknown c++ exception messages might go away.

Thanks!!!

Indeed worked!!!

Gabor

Edit: I’m on MacOS 10.15.5 and using R version 4.0.0 (2020-04-24)

@bgoodri @coatless I recently, accidentally updated RStan to 2.21 and Rcpp. I tried to uninstall it and reinstall Rcpp from drat (i.e., install.packages("Rcpp", repos = "https://rcppcore.github.io/drat")) but I now get

Warning in install.packages :
  unable to access index for repository https://rcppcore.github.io/drat/bin/macosx/contrib/4.0:
  cannot open URL 'https://rcppcore.github.io/drat/bin/macosx/contrib/4.0/PACKAGES'

If I just install the current Rcpp and then try to install RStan, I get the following error:

In file included from stan_fit.cpp:33:
In file included from ./stan/services/diagnose/diagnose.hpp:10:
In file included from ./stan/model/test_gradients.hpp:7:
In file included from ./stan/model/log_prob_grad.hpp:4:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/rev/mat.hpp:51:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/rev/mat/fun/squared_distance.hpp:27:11: warning: unused type alias 'idx_t' [-Wunused-local-typedef]
    using idx_t = typename index_type<matrix_v>::type;
          ^
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/rev/mat/fun/squared_distance.hpp:64:11: warning: unused type alias 'idx_t' [-Wunused-local-typedef]
    using idx_t = typename index_type<matrix_d>::type;
          ^
26 warnings generated.
ar -rs ../inst/lib//libStanServices.a stan_fit.o stan_fit_base.o
ar: creating archive ../inst/lib//libStanServices.a
installing to /Library/Frameworks/R.framework/Versions/4.0/Resources/library/00LOCK-rstan/00new/rstan/libs
** R
** inst
** byte-compile and prepare package for lazy loading
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/libs/Rcpp.so':
  dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/libs/Rcpp.so, 6): Symbol not found: _EXTPTR_PTR
  Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/libs/Rcpp.so
  Expected in: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libR.dylib
 in /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/libs/Rcpp.so
Calls: <Anonymous> ... asNamespace -> loadNamespace -> library.dynam -> dyn.load
Execution halted
ERROR: lazy loading failed for package ā€˜rstan’
* removing ā€˜/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rstan’
Warning in install.packages :
  installation of package ā€˜rstan’ had non-zero exit status

The downloaded source packages are in
	ā€˜/private/var/folders/zz/dvtr7nq911q1m2m0583x4tv40000gn/T/Rtmp7Oufnp/downloaded_packages’

Any ideas?

I would try installing Rcpp from source (either from CRAN or GitHub) but it is supposed to work if everything is using XCode’s clang++.