# Struggling to get CmdStan working on Mac OS Big Sur

**URL:** <https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774>\
**Category:** CmdStan\
**Created:** [December 12, 2020, 7:44pm UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774 "2020-12-12T19:44:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![hwilde](https://avatars.discourse-cdn.com/v4/letter/h/f9ae1b/32.png) [@hwilde](https://discourse.mc-stan.org/u/hwilde)\
**Post date:** [December 12, 2020, 7:44pm UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/1 "2020-12-12T19:44:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nicokist](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/nicokist/32/9155_2.png) [@nicokist](https://discourse.mc-stan.org/u/nicokist)\
**Post date:** [December 12, 2020, 11:45pm UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/2 "2020-12-12T23:45:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hwilde](https://avatars.discourse-cdn.com/v4/letter/h/f9ae1b/32.png) [@hwilde](https://discourse.mc-stan.org/u/hwilde)\
**Post date:** [December 13, 2020, 10:26am UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/3 "2020-12-13T10:26:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hwilde](https://avatars.discourse-cdn.com/v4/letter/h/f9ae1b/32.png) [@hwilde](https://discourse.mc-stan.org/u/hwilde)\
**Post date:** [December 13, 2020, 10:36am UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/4 "2020-12-13T10:36:58Z")

</div>

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.

```

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [December 13, 2020, 10:37am UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/5 "2020-12-13T10:37:29Z")

</div>

What happens if you try rebuild\_cmdstan() inside cmdstanr?

---

<div class="post-metadata">

**Author:** ![hwilde](https://avatars.discourse-cdn.com/v4/letter/h/f9ae1b/32.png) [@hwilde](https://discourse.mc-stan.org/u/hwilde)\
**Post date:** [December 13, 2020, 10:45am UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/6 "2020-12-13T10:45:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [December 13, 2020, 11:53am UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/7 "2020-12-13T11:53:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [December 13, 2020, 5:28pm UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/8 "2020-12-13T17:28:08Z")

</div>

> [@hwilde](#):
>
> ```no-highlight
> 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.
> 
> ```

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

> <https://github.com/stan-dev/cmdstanr/blob/d0c0f7797f3e8715bd85cafc4c31d73b0884ef95/R/model.R#L508-L511>

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

---

<div class="post-metadata">

**Author:** ![rok\_cesnovar](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@rok\_cesnovar](https://discourse.mc-stan.org/u/rok_cesnovar)\
**Post date:** [December 13, 2020, 5:38pm UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/9 "2020-12-13T17:38:47Z")

</div>

Maybe, yeah.

---

<div class="post-metadata">

**Author:** ![jonah](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jonah/32/200_2.png) [@jonah](https://discourse.mc-stan.org/u/jonah)\
**Post date:** [December 13, 2020, 5:44pm UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/10 "2020-12-13T17:44:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mitzimorris](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mitzimorris/32/29_2.png) [@mitzimorris](https://discourse.mc-stan.org/u/mitzimorris)\
**Post date:** [December 13, 2020, 6:05pm UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/11 "2020-12-13T18:05:26Z")

</div>

> [@Upgrade to MacOS Big Sur - CmdStan and CmdStanPy notes](https://discourse.mc-stan.org/t/upgrade-to-macos-big-sur-cmdstan-and-cmdstanpy-notes/19403):
>
> I upgraded from High Sierra to Big Sur, this meant that I hit some XCode changes. These were solved via the following two commands: xcode-select --install sudo xcode-select -switch /Library/Developer/CommandLineTools (perhaps the xcode-select -switch isn’t necessary when upgrading from Catalina) Then I went to my existing install of the GitHub CmdStan repo, which had existing CmdStan binaries and header files and tried to compile a model. This failed because the PCH header file was out of d…

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

---

<div class="post-metadata">

**Author:** ![Techno\_Viper](https://avatars.discourse-cdn.com/v4/letter/t/e68b1a/32.png) [@Techno\_Viper](https://discourse.mc-stan.org/u/Techno_Viper)\
**Post date:** [September 13, 2022, 5:55pm UTC](https://discourse.mc-stan.org/t/struggling-to-get-cmdstan-working-on-mac-os-big-sur/19774/12 "2022-09-13T17:55:05Z")

</div>

worked for me! thank you
