Unable to compile `Bernoulli` example on macOS Monterey 12.6.1

I’m unable to compile the example Bernoulli model on my macOS Monterey 12.6.1. I can compile CmdStan 2.30.1, but Bernoulli crashes at the linking stage:

make examples/bernoulli/bernoulli
g++ -I /opt/local/include/mpich-mp -fopenmp -std=c++1y -D_REENTRANT -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials    -DBOOST_DISABLE_ASSERTS          -c -MT stan/src/stan/model/model_header.hpp.gch -MT stan/src/stan/model/model_header.d -MM -E -MG -MP -MF stan/src/stan/model/model_header.d stan/src/stan/model/model_header.hpp
g++ -I /opt/local/include/mpich-mp -fopenmp -std=c++1y -D_REENTRANT -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials    -DBOOST_DISABLE_ASSERTS          -c -MT src/cmdstan/main.o -MM -E -MG -MP -MF src/cmdstan/main.d src/cmdstan/main.cpp

--- Translating Stan model to C++ code ---
bin/stanc  --o=examples/bernoulli/bernoulli.hpp examples/bernoulli/bernoulli.stan

--- Compiling, linking C++ code ---
mpic++ -fopenmp -std=c++1y -D_REENTRANT -Wno-ignored-attributes -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -DBOOST_DISABLE_ASSERTS -c -Wno-ignored-attributes -Wno-ignored-attributes   -x c++ -o examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp
mpic++ -fopenmp -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include    -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I /opt/local/include/mpich-mp/ -I /opt/local/include/libomp/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.78.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials    -DBOOST_DISABLE_ASSERTS                -Wl,-L,"/Users/mabalenk/repo/git/smcs-gpu/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/Users/mabalenk/repo/git/smcs-gpu/stan/lib/stan_math/lib/tbb" examples/bernoulli/bernoulli.o src/cmdstan/main.o        -Wl,-L,"/Users/mabalenk/repo/git/smcs3/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/Users/mabalenk/repo/git/smcs3/stan/lib/stan_math/lib/tbb"   stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_nvecserial.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_cvodes.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_idas.a stan/lib/stan_math/lib/sundials_6.1.1/lib/libsundials_kinsol.a  stan/lib/stan_math/lib/tbb/libtbb.dylib stan/lib/stan_math/lib/tbb/libtbbmalloc.dylib stan/lib/stan_math/lib/tbb/libtbbmalloc_proxy.dylib -o examples/bernoulli/bernoulli
0  0x10117bffa  __assert_rtn + 139
1  0x100faf28d  mach_o::relocatable::Parser<x86_64>::parse(mach_o::relocatable::ParserOptions const&) + 4989
2  0x100f9ff8f  mach_o::relocatable::Parser<x86_64>::parse(unsigned char const*, unsigned long long, char const*, long, ld::File::Ordinal, mach_o::relocatable::ParserOptions const&) + 207
3  0x1010169d4  ld::tool::InputFiles::makeFile(Options::FileInfo const&, bool) + 2036
4  0x101019fa0  ___ZN2ld4tool10InputFilesC2ER7Options_block_invoke + 48
5  0x7ff806a6134a  _dispatch_client_callout2 + 8
6  0x7ff806a728f5  _dispatch_apply_invoke + 213
7  0x7ff806a61317  _dispatch_client_callout + 8
8  0x7ff806a70c0c  _dispatch_root_queue_drain + 673
9  0x7ff806a7125c  _dispatch_worker_thread2 + 160
10  0x7ff806c14f8a  _pthread_wqthread + 256
A linker snapshot was created at:
	/tmp/bernoulli-2022-11-01-161946.ld-snapshot
ld: Assertion failed: (_file->_atomsArrayCount == computedAtomCount && "more atoms allocated than expected"), function parse, file macho_relocatable_file.cpp, line 2061.
collect2: error: ld returned 1 exit status
make: *** [make/program:65: examples/bernoulli/bernoulli] Error 1

I’m using GNU compiler toolchain ver. 12.2.0:

gcc (MacPorts gcc12 12.2.0_0+stdlib_flag) 12.2.0

Have you tried using Apple Clang (from xcode) instead of GCC?

Yes, I have. Using Apple’s clang compilation crashed at a different stage. I will try again and post the error here. Thank you!