Cmdstan model compilation fails after conda installation (Big Sur)

I have been unable to use cmdstan due to compiler issues that are obscure to me. Today I re-installed cmdstan through conda. (I also tried installing via cmdstanr but ran into the same issue)… The conda installation seems to work, but when I try to compile an example model it fails, complaining about missing functions (I think? see below).

I’ve tried most advice I’ve seen here and on Github, but I must be missing something. Any suggestions would be appreciated. Thanks in advance!

Other info:

  • MacBook Pro with Intel processor
  • Operating System: MacOS 11.6 (Big Sur)
  • CmdStan Version: 2.29.2
  • Compiler/Toolkit: conda
  • which clang returns the conda version of clang (miniconda3/envs/stan-env/bin/clang)
  • which g++ returns /usr/bin/g++

Here’s the output when I run make examples/bernoulli/bernoulli:

(stan-env) ~/opt/miniconda3/envs/stan-env/bin/cmdstan ᐅ make examples/bernoulli/bernoulli


--- Compiling pre-compiled header. This might take a few seconds. ---
x86_64-apple-darwin13.4.0-clang++ -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 /Users/wpmarble/opt/miniconda3/envs/stan-env/include -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT -Wno-ignored-attributes      -I /Users/wpmarble/opt/miniconda3/envs/stan-env/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.75.0 -I stan/lib/stan_math/lib/sundials_6.0.0/include -I stan/lib/stan_math/lib/sundials_6.0.0/src/sundials -D_FORTIFY_SOURCE=2 -isystem /Users/wpmarble/opt/miniconda3/envs/stan-env/include    -DBOOST_DISABLE_ASSERTS   -DTBB_INTERFACE_NEW  -DTBB_INTERFACE_NEW     -c stan/src/stan/model/model_header.hpp -o stan/src/stan/model/model_header.hpp.gch
In file included from stan/src/stan/model/model_header.hpp:4:
In file included from stan/lib/stan_math/stan/math.hpp:19:
In file included from stan/lib/stan_math/stan/math/rev.hpp:4:
In file included from stan/lib/stan_math/stan/math/prim/fun/Eigen.hpp:22:
In file included from stan/lib/stan_math/lib/eigen_3.3.9/Eigen/Dense:1:
In file included from stan/lib/stan_math/lib/eigen_3.3.9/Eigen/Core:96:
In file included from /Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/complex:235:
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:321:9: error: no member named 'signbit' in the global namespace
using ::signbit _LIBCPP_USING_IF_EXISTS;
      ~~^
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:322:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify _LIBCPP_USING_IF_EXISTS;
      ~~^
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:323:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite _LIBCPP_USING_IF_EXISTS;
      ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:752:12: note: 'finite' declared here
extern int finite(double)
           ^
In file included from stan/src/stan/model/model_header.hpp:4:
In file included from stan/lib/stan_math/stan/math.hpp:19:
In file included from stan/lib/stan_math/stan/math/rev.hpp:4:
In file included from stan/lib/stan_math/stan/math/prim/fun/Eigen.hpp:22:
In file included from stan/lib/stan_math/lib/eigen_3.3.9/Eigen/Dense:1:
In file included from stan/lib/stan_math/lib/eigen_3.3.9/Eigen/Core:96:
In file included from /Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/complex:235:
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:324:9: error: no member named 'isinf' in the global namespace
using ::isinf _LIBCPP_USING_IF_EXISTS;
      ~~^
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:325:9: error: no member named 'isnan' in the global namespace
using ::isnan _LIBCPP_USING_IF_EXISTS;
      ~~^
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:326:9: error: no member named 'isnormal' in the global namespace
using ::isnormal _LIBCPP_USING_IF_EXISTS;
      ~~^
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:327:9: error: no member named 'isgreater' in the global namespace
using ::isgreater _LIBCPP_USING_IF_EXISTS;
      ~~^
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:328:9: error: no member named 'isgreaterequal' in the global namespace
using ::isgreaterequal _LIBCPP_USING_IF_EXISTS;
      ~~^
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:329:9: error: no member named 'isless' in the global namespace
using ::isless _LIBCPP_USING_IF_EXISTS;
      ~~^
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:330:9: error: no member named 'islessequal' in the global namespace
using ::islessequal _LIBCPP_USING_IF_EXISTS;
      ~~^
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:331:9: error: no member named 'islessgreater' in the global namespace
using ::islessgreater _LIBCPP_USING_IF_EXISTS;
      ~~^
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:332:9: error: no member named 'isunordered' in the global namespace
using ::isunordered _LIBCPP_USING_IF_EXISTS;
      ~~^
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:333:9: error: no member named 'isunordered' in the global namespace
using ::isunordered _LIBCPP_USING_IF_EXISTS;
      ~~^
In file included from stan/src/stan/model/model_header.hpp:4:
In file included from stan/lib/stan_math/stan/math.hpp:19:
In file included from stan/lib/stan_math/stan/math/rev.hpp:4:
In file included from stan/lib/stan_math/stan/math/prim/fun/Eigen.hpp:22:
In file included from stan/lib/stan_math/lib/eigen_3.3.9/Eigen/Dense:1:
In file included from stan/lib/stan_math/lib/eigen_3.3.9/Eigen/Core:374:
stan/lib/stan_math/lib/eigen_3.3.9/Eigen/src/Core/MathFunctions.h:722:16: error: no member named 'isfinite' in namespace 'std'; did you mean 'finite'?
    using std::isfinite;
          ~~~~~^~~~~~~~
               finite
/Users/wpmarble/opt/miniconda3/envs/stan-env/bin/../include/c++/v1/cmath:323:9: note: 'finite' declared here
using ::isfinite _LIBCPP_USING_IF_EXISTS;
        ^
In file included from stan/src/stan/model/model_header.hpp:4:
In file included from stan/lib/stan_math/stan/math.hpp:19:
In file included from stan/lib/stan_math/stan/math/rev.hpp:4:
In file included from stan/lib/stan_math/stan/math/prim/fun/Eigen.hpp:22:
In file included from stan/lib/stan_math/lib/eigen_3.3.9/Eigen/Dense:1:
In file included from stan/lib/stan_math/lib/eigen_3.3.9/Eigen/Core:374:
stan/lib/stan_math/lib/eigen_3.3.9/Eigen/src/Core/MathFunctions.h:737:16: error: no member named 'isinf' in namespace 'std'
    using std::isinf;
          ~~~~~^
stan/lib/stan_math/lib/eigen_3.3.9/Eigen/src/Core/MathFunctions.h:752:16: error: no member named 'isnan' in namespace 'std'
    using std::isnan;
          ~~~~~^
In file included from stan/src/stan/model/model_header.hpp:4:
In file included from stan/lib/stan_math/stan/math.hpp:19:
In file included from stan/lib/stan_math/stan/math/rev.hpp:8:
In file included from stan/lib/stan_math/stan/math/rev/core.hpp:10:
In file included from stan/lib/stan_math/stan/math/rev/core/chainable_object.hpp:6:
In file included from stan/lib/stan_math/stan/math/rev/core/typedefs.hpp:7:
In file included from stan/lib/stan_math/stan/math/rev/core/Eigen_NumTraits.hpp:5:
In file included from stan/lib/stan_math/stan/math/prim/core.hpp:4:
In file included from stan/lib/stan_math/stan/math/prim/core/init_threadpool_tbb.hpp:6:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast.hpp:32:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/try_lexical_convert.hpp:44:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/detail/converter_lexical.hpp:54:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/detail/converter_lexical_streams.hpp:63:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/detail/inf_nan.hpp:34:
stan/lib/stan_math/lib/boost_1.75.0/boost/math/special_functions/sign.hpp:30:17: error: no member named 'signbit' in namespace 'std'; did you mean simply 'signbit'?
        return (std::signbit)(x) ? 1 : 0;
                ^~~~~~~~~~~~
                signbit
stan/lib/stan_math/lib/boost_1.75.0/boost/math/special_functions/math_fwd.hpp:891:8: note: 'signbit' declared here
   int signbit BOOST_NO_MACRO_EXPAND(T x);
       ^
In file included from stan/src/stan/model/model_header.hpp:4:
In file included from stan/lib/stan_math/stan/math.hpp:19:
In file included from stan/lib/stan_math/stan/math/rev.hpp:8:
In file included from stan/lib/stan_math/stan/math/rev/core.hpp:10:
In file included from stan/lib/stan_math/stan/math/rev/core/chainable_object.hpp:6:
In file included from stan/lib/stan_math/stan/math/rev/core/typedefs.hpp:7:
In file included from stan/lib/stan_math/stan/math/rev/core/Eigen_NumTraits.hpp:5:
In file included from stan/lib/stan_math/stan/math/prim/core.hpp:4:
In file included from stan/lib/stan_math/stan/math/prim/core/init_threadpool_tbb.hpp:6:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast.hpp:32:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/try_lexical_convert.hpp:44:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/detail/converter_lexical.hpp:54:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/detail/converter_lexical_streams.hpp:63:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/detail/inf_nan.hpp:35:
stan/lib/stan_math/lib/boost_1.75.0/boost/math/special_functions/fpclassify.hpp:155:12: error: no member named 'fpclassify' in namespace 'std'; did you mean simply 'fpclassify'?
   return (std::fpclassify)(t);
           ^~~~~~~~~~~~~~~
           fpclassify
stan/lib/stan_math/lib/boost_1.75.0/boost/math/special_functions/math_fwd.hpp:876:8: note: 'fpclassify' declared here
   int fpclassify BOOST_NO_MACRO_EXPAND(T t);
       ^
In file included from stan/src/stan/model/model_header.hpp:4:
In file included from stan/lib/stan_math/stan/math.hpp:19:
In file included from stan/lib/stan_math/stan/math/rev.hpp:8:
In file included from stan/lib/stan_math/stan/math/rev/core.hpp:10:
In file included from stan/lib/stan_math/stan/math/rev/core/chainable_object.hpp:6:
In file included from stan/lib/stan_math/stan/math/rev/core/typedefs.hpp:7:
In file included from stan/lib/stan_math/stan/math/rev/core/Eigen_NumTraits.hpp:5:
In file included from stan/lib/stan_math/stan/math/prim/core.hpp:4:
In file included from stan/lib/stan_math/stan/math/prim/core/init_threadpool_tbb.hpp:6:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast.hpp:32:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/try_lexical_convert.hpp:44:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/detail/converter_lexical.hpp:54:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/detail/converter_lexical_streams.hpp:63:
In file included from stan/lib/stan_math/lib/boost_1.75.0/boost/lexical_cast/detail/inf_nan.hpp:35:
stan/lib/stan_math/lib/boost_1.75.0/boost/math/special_functions/fpclassify.hpp:314:17: error: no member named 'isfinite' in namespace 'std'; did you mean simply 'isfinite'?
        return (std::isfinite)(x);
                ^~~~~~~~~~~~~
                isfinite
stan/lib/stan_math/lib/boost_1.75.0/boost/math/special_functions/math_fwd.hpp:879:9: note: 'isfinite' declared here
   bool isfinite BOOST_NO_MACRO_EXPAND(T z);
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [make/program:27: stan/src/stan/model/model_header.hpp.gch] Error 1

Do you have the xcode toolchain installed (e.g., can you run clang --version when conda is not active)? If so, what version is this at?

We’ve had reports of the conda install not working on MacOS, it seems like the issue is difficult to pin down in general.

Looks like I have Homebrew clang as the default, though I think I have the Xcode toolchain installed as well.

(base) ~ ᐅ clang --version
Homebrew clang version 13.0.1
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
(base) ~ ᐅ which -a clang
/usr/local/opt/llvm/bin/clang
/usr/bin/clang

This isn’t immediately a resolution to the conda problem, but you may have more success with the cmdstanr approach if you use the XCode clang rather than homebrew, I believe previous reports have been that the homebrew clang doesn’t play as nice.

For conda, could you post both the results of conda info and conda list?

Thanks for the help!

Basic question: can I do this simply by putting usr/bin ahead of usr/local/opt/llvm/bin in my PATH variable?

From within the stan-env conda environment:

(stan-env) ~ ᐅ conda info

     active environment : stan-env
    active env location : /Users/wpmarble/opt/miniconda3/envs/stan-env
            shell level : 2
       user config file : /Users/wpmarble/.condarc
 populated config files :
          conda version : 4.13.0
    conda-build version : not installed
         python version : 3.9.12.final.0
       virtual packages : __osx=10.16=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /Users/wpmarble/opt/miniconda3  (writable)
      conda av data dir : /Users/wpmarble/opt/miniconda3/etc/conda
  conda av metadata url : None
           channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /Users/wpmarble/opt/miniconda3/pkgs
                          /Users/wpmarble/.conda/pkgs
       envs directories : /Users/wpmarble/opt/miniconda3/envs
                          /Users/wpmarble/.conda/envs
               platform : osx-64
             user-agent : conda/4.13.0 requests/2.28.1 CPython/3.9.12 Darwin/20.6.0 OSX/10.16
                UID:GID : 501:20
             netrc file : None
           offline mode : False

(stan-env) ~ ᐅ conda list
# packages in environment at /Users/wpmarble/opt/miniconda3/envs/stan-env:
#
# Name                    Version                   Build  Channel
cctools_osx-64            949.0.1             hc7db93f_23
clang                     12.0.0               hecd8cb5_2
clang-12                  12.0.0          default_hfcad0e5_2
clang_osx-64              12.0.0               h7ad7729_2
clangxx                   12.0.0          default_hfcad0e5_2
clangxx_osx-64            12.0.0               he0c6f94_2
cmdstan                   2.29.2               h775853c_0    conda-forge
compiler-rt               12.0.0               hd87ff74_2
compiler-rt_osx-64        12.0.0               hfb26b64_2
ld64_osx-64               530                 h70f3046_23
ldid                      2.1.2                h6a69015_3    conda-forge
libclang-cpp12            12.0.0          default_hfcad0e5_2
libcxx                    14.0.6               hce7ea42_0    conda-forge
libllvm12                 12.0.0               h9b2ccf5_3
libzlib                   1.2.12               hfe4f2af_2    conda-forge
llvm-tools                12.0.0               h9b2ccf5_3
make                      4.3                  h22f3db7_1    conda-forge
tapi                      1000.10.8            ha1b3eb9_0
tbb                       2021.5.0             hbb4e6a2_1    conda-forge
tbb-devel                 2021.5.0             hbb4e6a2_1    conda-forge
zlib                      1.2.12               hfe4f2af_2    conda-forge

From within R, Sys.getenv("PATH") tells me /usr/bin is the first directory listed. Installation of cmdstan using cmdstanr::install_cmdstan() failed with similar error messages as in my original post.

I then tried putting the Xcode path first — found by running xcodebuild -find clang. The cmdstanr installation of cmdstan also failed then, with error messages like the following:

ld: library not found for -ldl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [libtbbmalloc.dylib] Error 1
make: *** [stan/lib/stan_math/lib/tbb/tbbmalloc.def] Error 2

What version is the xcode clang?

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

bumping to see if anyone has other suggestions.