Dealing with Catalina II

.Renviron in place, and running your function looks like this:

/Users/torkarr/Library/R/3.6/library/Rcpp/libs/Rcpp.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.6.0)
/Users/torkarr/Library/R/3.6/library/scales/libs/scales.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/tidyselect/libs/tidyselect.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/dplyr/libs/dplyr.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/rstan/libs/rstan.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.6.0)
/var/folders/5p/dlcj_kd94bx83r83k_d77j54pspdk5/T//Rtmp1dxXa1/file8434301b38ac.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.7.0)

And compiler output:

Compilation argument:
/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file86f81f777c59.cpp 2> file86f81f777c59.cpp.err.txt
/usr/local/clang7/bin/clang++ -stdlib=libc++ -nostdinc++ -I/usr/local/clang7/include/c++/v1 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Users/torkarr/Library/R/3.6/library/Rcpp/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/unsupported" -I"/Users/torkarr/Library/R/3.6/library/BH/include" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/src/" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/" -I"/Users/torkarr/Library/R/3.6/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c file86f81f777c59.cpp -o file86f81f777c59.o
/usr/local/clang7/bin/clang++ -L/Library/Frameworks/R.framework/Resources/lib/libc++.1.dylib -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o file86f81f777c59.so file86f81f777c59.o -L/Users/torkarr/Library/R/3.6/library/StanHeaders/lib/ -lStanHeaders -F/Library/Frameworks/R.framework/… -framework R -Wl,-framework -Wl,CoreFoundation

What about just

Rcpp::sourceCpp(code = 
'
#include <Rcpp.h>

// [[Rcpp::export]]
int throw_exception() { 
  std::stringstream errmsg; errmsg << "this is the expected behavior";
  throw std::domain_error(errmsg.str()); 
  return 0;
}
'
)

throw_exception()

?

Restarted RStudio and ran your code:
Error in throw_exception() : this is the expected behavior

OK. And you have StanHeaders and rstan from CRAN?

Sure. BUT, let me try it out again. What’s the best way to clean out StanHeaders and rstan completely?

remove.packages("rstan")
remove.packages("StanHeaders")
file.remove(".RData")

restart

install.packages("rstan", dependencies = TRUE)

Still get Error in throw_exception() : this is the expected behavior. I’ll rerun the example now.

I got the same

Chain 1: Iteration: 1 / 2000 [ 0%] (Warmup)
[1] “Error in sampler$call_sampler(args_list[[i]]) : "
[2] " c++ exception (unknown reason)”
error occurred during calling the sampler; sampling not done

Here’s the verbose output:

Compilation argument:
/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file91bf424c6003.cpp 2> file91bf424c6003.cpp.err.txt
/usr/local/clang7/bin/clang++ -stdlib=libc++ -nostdinc++ -I/usr/local/clang7/include/c++/v1 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Users/torkarr/Library/R/3.6/library/Rcpp/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/unsupported" -I"/Users/torkarr/Library/R/3.6/library/BH/include" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/src/" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/" -I"/Users/torkarr/Library/R/3.6/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c file91bf424c6003.cpp -o file91bf424c6003.o
/usr/local/clang7/bin/clang++ -L/Library/Frameworks/R.framework/Resources/lib/libc++.1.dylib -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o file91bf424c6003.so file91bf424c6003.o -L/Users/torkarr/Library/R/3.6/library/StanHeaders/lib/ -lStanHeaders -F/Library/Frameworks/R.framework/… -framework R -Wl,-framework -Wl,CoreFoundation

And

dlls <- getLoadedDLLs()
paths <- vapply(dlls, `[[`, "path", FUN.VALUE = character(1))
invisible(lapply(paths, function(path) {
  
  if (!file.exists(path))
    return(FALSE)
  
  output <- system(paste("otool -L", shQuote(path), "| grep libc++ || true"),
                   intern = TRUE)
  if (length(output) == 0)
    return(FALSE)
  
  writeLines(paste0(path, ":"))
  writeLines(output)
  
}))

still has /usr/lib/libc++.1.dylib at the end?

/Users/torkarr/Library/R/3.6/library/Rcpp/libs/Rcpp.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.6.0)
/Users/torkarr/Library/R/3.6/library/scales/libs/scales.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/tidyselect/libs/tidyselect.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/dplyr/libs/dplyr.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/rstan/libs/rstan.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/var/folders/5p/dlcj_kd94bx83r83k_d77j54pspdk5/T//RtmpQ45ZaX/file91bf424c6003.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.7.0)

I don’t know how that is possible. We’ll need additional Mac expertise.

In the meantime, try changing

-L$(R_HOME)/lib/libc++.1.dylib

to

-L/usr/local/clang7/lib

in ~/.R/Makevars.

Now it sampled correctly…
Your DLL code says this:

/Users/torkarr/Library/R/3.6/library/Rcpp/libs/Rcpp.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.6.0)
/Users/torkarr/Library/R/3.6/library/scales/libs/scales.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/tidyselect/libs/tidyselect.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/dplyr/libs/dplyr.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/rstan/libs/rstan.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/var/folders/5p/dlcj_kd94bx83r83k_d77j54pspdk5/T//RtmpDpq1C9/file9780549a963b.so:
/usr/local/clang7/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)

And compilation arguments are:

Compilation argument:
/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file9780549a963b.cpp 2> file9780549a963b.cpp.err.txt
/usr/local/clang7/bin/clang++ -stdlib=libc++ -nostdinc++ -I/usr/local/clang7/include/c++/v1 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Users/torkarr/Library/R/3.6/library/Rcpp/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/unsupported" -I"/Users/torkarr/Library/R/3.6/library/BH/include" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/src/" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/" -I"/Users/torkarr/Library/R/3.6/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c file9780549a963b.cpp -o file9780549a963b.o
/usr/local/clang7/bin/clang++ -L/usr/local/clang7/lib -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o file9780549a963b.so file9780549a963b.o -L/Users/torkarr/Library/R/3.6/library/StanHeaders/lib/ -lStanHeaders -F/Library/Frameworks/R.framework/… -framework R -Wl,-framework -Wl,CoreFoundation

I need to fetch my kids now so will check later this evening (Swedish time).

Is /Library/Frameworks/R.framework/Resources/lib/libc++1.dylib a symlink to /usr/lib/libc++.1.dylib in Sweden?

Not sure if it helps at all, but in case any linux-based devs want to get hands-on with Catalina, I just found these instructions for setting it up as a VM (inc. auto-downloading the OS ISO): https://github.com/foxlet/macOS-Simple-KVM/blob/master/README.md

1 Like

Well, in Sweden there’s no libc++1.dylib ;) But I have a libc++.1.dylib and it’s not a link:

% ls -lsa libc++.1.dylib
1656 -rwxrwxr-x 1 root admin 845100 Jul 6 04:12 libc++.1.dylib

OK. Try agin with

-L$(R_HOME)/lib

in ~/.R/Makevars instead of

-L/usr/local/clang7/lib

Got an unknown reason during sampling again. Previously it sampled nicely with -L/usr/local/clang7/lib

Output below:

Compilation argument:
/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB fileac4a36d3023f.cpp 2> fileac4a36d3023f.cpp.err.txt
/usr/local/clang7/bin/clang++ -stdlib=libc++ -nostdinc++ -I/usr/local/clang7/include/c++/v1 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Users/torkarr/Library/R/3.6/library/Rcpp/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/unsupported" -I"/Users/torkarr/Library/R/3.6/library/BH/include" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/src/" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/" -I"/Users/torkarr/Library/R/3.6/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c fileac4a36d3023f.cpp -o fileac4a36d3023f.o
/usr/local/clang7/bin/clang++ -L/Library/Frameworks/R.framework/Resources/lib -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o fileac4a36d3023f.so fileac4a36d3023f.o -L/Users/torkarr/Library/R/3.6/library/StanHeaders/lib/ -lStanHeaders -F/Library/Frameworks/R.framework/… -framework R -Wl,-framework -Wl,CoreFoundation

and,

/Users/torkarr/Library/R/3.6/library/Rcpp/libs/Rcpp.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.6.0)
/Users/torkarr/Library/R/3.6/library/scales/libs/scales.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/tidyselect/libs/tidyselect.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/dplyr/libs/dplyr.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/rstan/libs/rstan.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/var/folders/5p/dlcj_kd94bx83r83k_d77j54pspdk5/T//Rtmp6fAMsg/fileac4a36d3023f.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.7.0)

Can you add a -lc++ at the end of

SHLIB_CXX14LD = /usr/local/clang7/bin/clang++ -L$(R_HOME)/lib/"

in ~/.R/Makevars .

Same error with the sampling.

Compilation argument:
/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB fileb7c99ed272e.cpp 2> fileb7c99ed272e.cpp.err.txt
/usr/local/clang7/bin/clang++ -stdlib=libc++ -nostdinc++ -I/usr/local/clang7/include/c++/v1 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Users/torkarr/Library/R/3.6/library/Rcpp/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/" -I"/Users/torkarr/Library/R/3.6/library/RcppEigen/include/unsupported" -I"/Users/torkarr/Library/R/3.6/library/BH/include" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/src/" -I"/Users/torkarr/Library/R/3.6/library/StanHeaders/include/" -I"/Users/torkarr/Library/R/3.6/library/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -c fileb7c99ed272e.cpp -o fileb7c99ed272e.o
/usr/local/clang7/bin/clang++ -L/Library/Frameworks/R.framework/Resources/lib -lc++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o fileb7c99ed272e.so fileb7c99ed272e.o -L/Users/torkarr/Library/R/3.6/library/StanHeaders/lib/ -lStanHeaders -F/Library/Frameworks/R.framework/… -framework R -Wl,-framework -Wl,CoreFoundation

/Users/torkarr/Library/R/3.6/library/Rcpp/libs/Rcpp.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.6.0)
/Users/torkarr/Library/R/3.6/library/scales/libs/scales.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/tidyselect/libs/tidyselect.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/dplyr/libs/dplyr.so:
/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/Users/torkarr/Library/R/3.6/library/rstan/libs/rstan.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/var/folders/5p/dlcj_kd94bx83r83k_d77j54pspdk5/T//RtmpaaeUD3/fileb7c99ed272e.so:
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 800.7.0)

And

example(cxxfunction, package = "inline", run.dontrun = TRUE)

links the DLLs to /usr/lib/libc++.1.dylib or to /Library/Frameworks/R.framework/Resources/lib/libc++.1.dylib?