Struggling to get CmdStan working on Mac OS Big Sur

I’m being forced to work on a new MacBook for a project I’ve just started and it came with Mac OS Big Sur, which I have heard has some problems (as these things always do when they first come out). I’ve tried following the standard procedure to install CmdStan:

xcode-select --install
cd ~
git clone https://github.com/stan-dev/cmdstan.git --recursive
cd cmdstan
make build -j6

I’ve tried reinstalling xcode CLT etc. the usual fixes, but no matter what I do I get the following error:

Failed to build Boost.Build build engine
Consult 'bootstrap.log' for more details

Looking in ‘bootstrap.log’ we see:

###
###
### Using 'clang' toolset.
###
###
x86_64-apple-darwin13.4.0-clang++ --version
clang version 9.0.1
Target: x86_64-apple-darwin13.4.0
Thread model: posix
InstalledDir: /usr/local/Caskroom/miniconda/base/envs/bayes/bin
###
###
x86_64-apple-darwin13.4.0-clang++ -x c++ -O3 -std=c++11 -march=core2 -mtune=haswell -mssse3 -ftree-vectorize -fPIC -fPIE -fstack-protector-strong -O2 -pipe -stdlib=libc++ -fvisibility-inlines-hidden -std=c++14 -fmessage-length=0 -isystem /usr/local/Caskroom/miniconda/base/envs/bayes/include -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_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.72.0 -I stan/lib/stan_math/lib/sundials_5.5.0/include -O3 -s -DNDEBUG builtins.cpp class.cpp command.cpp compile.cpp constants.cpp cwd.cpp debug.cpp debugger.cpp execcmd.cpp filesys.cpp frames.cpp function.cpp glob.cpp hash.cpp hcache.cpp hdrmacro.cpp headers.cpp jam.cpp jambase.cpp jamgram.cpp lists.cpp make.cpp make1.cpp md5.cpp mem.cpp modules.cpp native.cpp object.cpp option.cpp output.cpp parse.cpp pathsys.cpp regexp.cpp rules.cpp scan.cpp search.cpp strings.cpp subst.cpp sysinfo.cpp timestamp.cpp variable.cpp w32_getreg.cpp modules/order.cpp modules/path.cpp modules/property-set.cpp modules/regex.cpp modules/sequence.cpp modules/set.cpp execunix.cpp fileunix.cpp pathunix.cpp -o b2
ld: warning: option -s is obsolete and being ignored
ld: unsupported tapi file type '!tapi-tbd' in YAML file '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd' for architecture x86_64
clang-9: error: linker command failed with exit code 1 (use -v to see invocation)

I’m noting that this seems to specify its using clang++ from my conda environment, not sure how to revert to xcode’s clt here? Regardless of the environment I try, I can’t seem to get this to work.

  • Operating System: Mac OS Big Sur
  • CmdStan Version: 2.25.0
  • Compiler/Toolkit: Xcode, Apple clang version 12.0.0 (clang-1200.0.32.27) and GNU Make 3.81

Thanks

You could try CXX=/usr/bin/clang++ make build to force make to use the builtin clang. Perhaps run make clean-all first.

2 Likes

Such a simple solution, I didn’t realise make could be prefix aliased explicitly, thank you so much!

1 Like

I spoke too soon potentially as I might need a bit more help. This has allowed cmdstan to build successfully, but when I go to use it via cmdstanr I get the following error, is there a way to specify this CXX flag globally?

Compiling Stan program...
error: stack protector mode differs in PCH file vs. current file
error: PCH file was compiled for the target 'x86_64-apple-macosx10.9.0' but the current translation unit is being compiled for target 'x86_64-apple-macosx11.0.0'
2 errors generated.
make: *** [/var/folders/rc/_df5n5md3vg8qs3wl_5lk0f80000gn/T/Rtmp6PbS5L/model-3822ebf8022] Error 1
Error: An error occured during compilation! See the message above for more information.

What happens if you try rebuild_cmdstan() inside cmdstanr?

This seems to work yes! Do you know what might have been the problem to avoid in the future?

The problem there is that Cmdstan uses a precompiled header (PCH) that speeds up compilation for up to a factor of 2. And when the PCH is compiled using some other compiler or an earlier version of the same compiler you need to rebuild cmdstan.

So far we have not found a way to automatically detect that in cmdstan so you need to run rebuild cmdstan manually whenever that occurs. This seems to come up on MacOS sometime when the xcode toolchain updates.

There is one possible solution to this, which is disabling precompiled headers, but that will slow down compilation for a factor of 2.

3 Likes

@rok_cesnovar It looks like these are different messages about the PCH than the messages we’re catching and warning about in cmdstanr:

Do you think it makes sense for us to instead just look for “PCH file” instead of the whole message?

1 Like

Maybe, yeah.

I can open an issue so we don’t forget to think about that.

1 Like

you should be able to do the same thing using CmdStanPy, FWIW