Error on running brm() ("Error in compileCode(f, code, <snip>")

I’m new to brms (today), and get the same error on running brm() from any of the vignettes I’ve tried. E.g. (from the “R replication code” here):

### fit the first model to the kidney data
fit1 <- brm(formula = time | cens(censored) ~ age * sex + disease 
            + (1 + age | patient), 
            data = kidney, family = lognormal(),
            prior = c(set_prior("normal(0,5)", class = "b"),
                      set_prior("cauchy(0,2)", class = "sd"),
                      set_prior("lkj(2)", class = "cor")),
            warmup = 1000, iter = 2000, chains = 4,
            control = list(adapt_delta = 0.95))

Here’s the error I get:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  In file included from 
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:52:
/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/rev/core/precomputed_gradients.hpp:86:60: 

warning: lambda capture 'this' is not used [-Wunused-lambda-capture]        container_gradients_(index_apply<N_containers>([&, this](auto... Is) {                                                           
^34 warnings and 1 error generated.make: *** [file12cb43550f58c.o] Error 1

(The only difference for different brm() calls being the file designation at the end of the message.)

I’ve tried Googling some of the terms from the error message, but haven’t made any headway. Any ideas/suggestions?

  • macOS 11.6
  • brms 2.16.2
  • Xcode 12.4 (not sure if that’s relevant…)

And in case it’s helpful, here the full console output (just prior to the above error message):

Compiling Stan program...
make cmd is
  make -f '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB='file12cb42246792f.so' OBJECTS='file12cb42246792f.o'

make would use
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c file12cb42246792f.cpp -o file12cb42246792f.o
if test  "zfile12cb42246792f.o" != "z"; then \
	  echo clang++ -mmacosx-version-min=10.13 -std=gnu++14 -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 file12cb42246792f.so file12cb42246792f.o  '/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppParallel/lib/' -ltbb -ltbbmalloc -ltbbmalloc_proxy  -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
	  clang++ -mmacosx-version-min=10.13 -std=gnu++14 -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 file12cb42246792f.so file12cb42246792f.o  '/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rstan/lib//libStanServices.a' -L'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/lib/' -lStanHeaders -L'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppParallel/lib/' -ltbb -ltbbmalloc -ltbbmalloc_proxy  -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
	fi

And here’s the output when I run system("clang++ -v") (as suggested in the vignette):

Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin