Building CmdStan on Debian Bullseye

I encountered the following trace when building CmdStan on a Debian server:

make[1]: Entering directory '/tmp/cmdstan-2.30.1/stan/lib/stan_math/lib/tbb'
g++ -c -MMD -O2 -g -DDO_ITT_NOTIFY -DUSE_PTHREAD -pthread -m64 -mrtm   -Wno-unknown-warning-option -Wno-deprecated-copy -Wno-missing-attributes -Wno-class-memaccess -Wno-sized-deallocation   -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1 -fno-rtti -fno-exceptions -D__TBBMALLOC_BUILD=1 -Wno-parentheses -Wno-sized-deallocation -fPIC -flifetime-dse=1 -I../tbb_2020.3/src -I../tbb_2020.3/src/rml/include -I../tbb_2020.3/include -I../tbb_2020.3/src/tbbmalloc -I../tbb_2020.3/src/tbbmalloc ../tbb_2020.3/src/tbbmalloc/backend.cpp
In file included from ../tbb_2020.3/include/tbb/tbb_config.h:36,
                 from ../tbb_2020.3/include/tbb/tbb_stddef.h:91,
                 from ../tbb_2020.3/src/tbbmalloc/Customize.h:21,
                 from ../tbb_2020.3/src/tbbmalloc/TypeDefinitions.h:54,
                 from ../tbb_2020.3/src/tbbmalloc/tbbmalloc_internal.h:21,
                 from ../tbb_2020.3/src/tbbmalloc/backend.cpp:19:
/usr/include/c++/10/cstddef:49:10: fatal error: bits/c++config.h: No such file or directory
   49 | #include <bits/c++config.h>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [/tmp/cmdstan-2.30.1/stan/lib/stan_math/lib/tbb_2020.3/build/Makefile.tbbmalloc:65: backend.o] Error 1
make[1]: Leaving directory '/tmp/cmdstan-2.30.1/stan/lib/stan_math/lib/tbb'
make: *** [stan/lib/stan_math/make/libraries:173: stan/lib/stan_math/lib/tbb/tbbmalloc.def] Error 2
make: *** Waiting for unfinished jobs....

I won’t bother you with how I figured out the solution, and instead just give it to you:

  1. Download the 2.30.1 release of CmdStan
  2. Download the orig and debian tarballs from Debian’s package site
  3. Extract tbb_2020.3-1.debian.tar.xz, keeping note of where the extracted debian directory is
  4. Extract tbb_2020.3.orig.tar.xz (obtained above) and cd into the extracted oneTBB-2020.3 directory
  5. Apply the following patches with this command (same order I did): patch -p1 < /PATH/TO/PATCH.patch: buildi386.patch, fixnonlinux.patch, linuxreleasedetect.patch, tweak-64bits-hppa-alpha.patch, adddebug.patch
  6. Rename the existing tbb_2020.3 directory at cmdstan-2.30.1/stan/lib/stan_math/lib
  7. Symlink your patched oneTBB-2020.3 directory to replace the above: ln -s /PATH/TO/oneTBB-2020.3 /PATH/TO/cmdstan-2.30.1/stan/lib/stan_math/lib/tbb_2020.3
  8. cd into your oneTBB-2020.3 directory and make the project. I had to do this from here, rather than allow CmdStan’s build system handle it
  9. If you’ve successfully built TBB, go back to the root cmdstan-2.30.1 directory and make build, which should work fine this time around.

My selection of patches is pretty arbitrary and I do not claim that is it precisely correct; I’m just a superstitious pigeon trying to make food appear here, sharing the dance that made that happen.

I posted this solution to Stan’s discourse forum, but it was immediately flagged as spam by the community there. Nice folks!


    Leave a Reply

    Your email address will not be published. Required fields are marked *