# cmdStan Intel TBB error when compiling model

**URL:** <https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618>\
**Category:** CmdStan\
**Created:** [January 27, 2025, 1:10pm UTC](https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618 "2025-01-27T13:10:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjcarter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mjcarter/32/18376_2.png) [@mjcarter](https://discourse.mc-stan.org/u/mjcarter)\
**Post date:** [January 27, 2025, 1:10pm UTC](https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618/1 "2025-01-27T13:10:27Z")

</div>

I run into an Intel TBB linking error when trying to compile the Bernoulli example model using a fresh installation of cmdStan.

- Operating System: CentOS Linux 7.9.2009
- GCC Compiler: 11.2.0
- cmdStan: v2.36.0

I configure my environment on the HPC server using:

```no-highlight
module load compilers/gcc/11.2.0

```

and then download / build cmdStan with:

```no-highlight
wget https://github.com/stan-dev/cmdstan/releases/download/v2.36.0/cmdstan-2.36.0.tar.gz
tar -xzf cmdstan-2.36.0.tar.gz
cd cmdstan-2.36.0
make build

```

which builds successfully without error

```no-highlight
--- CmdStan v2.36.0 built ---

```

However, when trying to compile the Bernoulli model with:

```no-highlight
make examples/bernoulli/bernoulli

```

I see the following error:

```no-highlight
/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/bin/g++ -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.84.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -I/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/include -DBOOST_DISABLE_ASSERTS -c -MT stan/src/stan/model/model_header.hpp.gch/model_header_11_2.hpp.gch -M -E -MG -MP -MF stan/src/stan/model/model_header.hpp.gch/model_header_11_2.d stan/src/stan/model/model_header.hpp
/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/bin/g++ -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.84.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -I/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/include -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 C++ code ---
/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/bin/g++ -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.84.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -I/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/include -DBOOST_DISABLE_ASSERTS -c -Wno-ignored-attributes -x c++ -o examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp

--- Linking model ---
/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/bin/g++ -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.84.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -I/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/include -DBOOST_DISABLE_ASSERTS -L/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/lib64 -Wl,-L,"/mnt/data1/users/mcarter/cmdstan/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/mnt/data1/users/mcarter/cmdstan/stan/lib/stan_math/lib/tbb" examples/bernoulli/bernoulli.o src/cmdstan/main.o -ltbb 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.so.2 -o examples/bernoulli/bernoulli
src/cmdstan/main.o: In function `cmdstan::command(int, char const**)':
main.cpp:(.text+0x2db7f): undefined reference to `tbb::interface7::internal::task_arena_base::internal_initialize()'
main.cpp:(.text+0x2f8fc): undefined reference to `tbb::interface9::global_control::internal_create()'
src/cmdstan/main.o: In function `tbb::interface7::task_arena::~task_arena()':
main.cpp:(.text._ZN3tbb10interface710task_arenaD2Ev[_ZN3tbb10interface710task_arenaD5Ev]+0x15): undefined reference to `tbb::interface7::internal::task_arena_base::internal_terminate()'
src/cmdstan/main.o: In function `tbb::interface9::global_control::~global_control()':
main.cpp:(.text._ZN3tbb10interface914global_controlD2Ev[_ZN3tbb10interface914global_controlD5Ev]+0x5): undefined reference to `tbb::interface9::global_control::internal_destroy()'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::invalid_argument@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::length_error::length_error(std::string const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::range_error::range_error(std::string const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_allocate_exception@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `std::bad_alloc::~bad_alloc()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::string::_Rep::_M_destroy(std::allocator<char> const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::bad_alloc::~bad_alloc()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_throw@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `std::string::_Rep::_M_dispose(std::allocator<char> const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `operator delete(void*)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::runtime_error::runtime_error(std::string const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::runtime_error::~runtime_error()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::length_error::~length_error()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::range_error::~range_error()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `operator new(unsigned long)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `vtable for __cxxabiv1::__ class_type_info@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_end_catch@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_rethrow@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::out_of_range@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::string::_Rep::_S_empty_rep_storage@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::invalid_argument::~invalid_argument()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::length_error@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_call_unexpected@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `__gxx_personality_v0@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `std::out_of_range::out_of_range(std::string const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_free_exception@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `operator delete[](void*)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::bad_alloc@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::range_error@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::exception::~exception()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::exception@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::runtime_error@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::out_of_range::~out_of_range()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `vtable for __cxxabiv1::__ si_class_type_info@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_begin_catch@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `vtable for __cxxabiv1::__ vmi_class_type_info@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `operator new[](unsigned long)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_pure_virtual@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `std::invalid_argument::invalid_argument(std::string const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `vtable for std::bad_alloc@GLIBCXX_3.4'
collect2: error: ld returned 1 exit status
make: *** [examples/bernoulli/bernoulli] Error 1
rm examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp

```

I’m a bit confused why these errors don’t appear whilst compiling cmdStan. Any suggestions?

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [January 27, 2025, 4:18pm UTC](https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618/2 "2025-01-27T16:18:06Z")

</div>

This is one for @stevebronder.

The only hints on our documentation page

[https://mc-stan.org/docs/cmdstan-guide/installation.html](https://mc-stan.org/docs/cmdstan-guide/installation.html)

are for Windows.

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [January 27, 2025, 9:17pm UTC](https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618/3 "2025-01-27T21:17:43Z")

</div>

```no-highlight
/lib/../lib64/libtbb.so

```

This implies TBB is being linked from the HPC system, not from CmdStan’s copy. This is actually probably a good thing, if you can get it working. The errors look like what happens when you’re trying to link a newer version of TBB than we expect, but we can ask cmdstan to use a newer version

On my cluster, this usually looks like

```no-highlight
module load compilers/gcc/11.2.0
module load intel/oneTBB # consult your HPC's specific name

```

and then in cmdstan/make/local, set

```no-highlight
TBB_CXX_TYPE=gcc
TBB_INTERFACE_NEW=true
TBB_INC=$(TBBROOT)/include/
TBB_LIB=$(TBBROOT)/lib/

```

(for me, my module system sets TBBROOT, ymmv)

---

<div class="post-metadata">

**Author:** ![mjcarter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mjcarter/32/18376_2.png) [@mjcarter](https://discourse.mc-stan.org/u/mjcarter)\
**Post date:** [January 28, 2025, 11:04am UTC](https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618/4 "2025-01-28T11:04:55Z")

</div>

Intel TBB is not installed as a package on the HPC system that I am using. A number of packages that ship with Intel TBB are available, but I have not loaded any of these (see below), so they shouldn’t change things in my environment.

```no-highlight
Currently Loaded Modulefiles:
  1) null 2) compilers/gcc/11.2.0

```

Is it possible to force Stan to compile against the packaged version of Intel TBB?

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [January 28, 2025, 2:41pm UTC](https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618/5 "2025-01-28T14:41:09Z")

</div>

Can you try compiling with `CXXFLAGS=-Wl,-v make examples/bernoulli/bernoulli`?

It may also be worth sharing the output of `make print-compiler-flags`

We need to understand why the system is picking up a different TBB before it’s possible to make it use another

---

<div class="post-metadata">

**Author:** ![mjcarter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/mjcarter/32/18376_2.png) [@mjcarter](https://discourse.mc-stan.org/u/mjcarter)\
**Post date:** [January 28, 2025, 3:26pm UTC](https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618/6 "2025-01-28T15:26:06Z")

</div>

Hi Brian,

Below is the output with `CXXFLAGS=-Wl,-v make ...`

```no-highlight
[mcarter@viz02[barkla] cmdstan-2.36.0]$ CXXFLAGS=-Wl,-v make examples/bernoulli/bernoulli

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

--- Compiling C++ code ---
/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/bin/g++ -Wl,-v -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.84.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -I/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/include -DBOOST_DISABLE_ASSERTS -DTBB_INTERFACE_NEW -DTBB_INTERFACE_NEW -c -Wno-ignored-attributes -x c++ -o examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp

--- Linking model ---
/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/bin/g++ -Wl,-v -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.84.0 -I stan/lib/stan_math/lib/sundials_6.1.1/include -I stan/lib/stan_math/lib/sundials_6.1.1/src/sundials -I/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/include -DBOOST_DISABLE_ASSERTS -DTBB_INTERFACE_NEW -DTBB_INTERFACE_NEW -L/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/lib64 -Wl,-L,"/mnt/data1/users/mcarter/cmdstan-2.36.0/stan/lib/stan_math/lib/tbb" -Wl,-rpath,"/mnt/data1/users/mcarter/cmdstan-2.36.0/stan/lib/stan_math/lib/tbb" examples/bernoulli/bernoulli.o src/cmdstan/main.o -ltbb 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.so.2 -o examples/bernoulli/bernoulli
collect2 version 11.2.0
/usr/bin/ld -plugin /opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/liblto_plugin.so -plugin-opt=/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper -plugin-opt=-fresolution=/tmp/ccekrBTP.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o examples/bernoulli/bernoulli /lib/../lib64/crt1.o /lib/../lib64/crti.o /opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/lib/gcc/x86_64-pc-linux-gnu/11.2.0/crtbegin.o -L/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/lib64 -L/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/lib/gcc/x86_64-pc-linux-gnu/11.2.0 -L/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../.. -v -L /mnt/data1/users/mcarter/cmdstan-2.36.0/stan/lib/stan_math/lib/tbb -rpath /mnt/data1/users/mcarter/cmdstan-2.36.0/stan/lib/stan_math/lib/tbb examples/bernoulli/bernoulli.o src/cmdstan/main.o -ltbb 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.so.2 -lstdc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc /opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/lib/gcc/x86_64-pc-linux-gnu/11.2.0/crtend.o /lib/../lib64/crtn.o
GNU ld version 2.27-44.base.el7_9.1
src/cmdstan/main.o: In function `cmdstan::command(int, char const**)':
main.cpp:(.text+0x2d92f): undefined reference to `tbb::interface7::internal::task_arena_base::internal_initialize()'
main.cpp:(.text+0x2f6ac): undefined reference to `tbb::interface9::global_control::internal_create()'
src/cmdstan/main.o: In function `tbb::interface7::task_arena::~task_arena()':
main.cpp:(.text._ZN3tbb10interface710task_arenaD2Ev[_ZN3tbb10interface710task_arenaD5Ev]+0x15): undefined reference to `tbb::interface7::internal::task_arena_base::internal_terminate()'
src/cmdstan/main.o: In function `tbb::interface9::global_control::~global_control()':
main.cpp:(.text._ZN3tbb10interface914global_controlD2Ev[_ZN3tbb10interface914global_controlD5Ev]+0x5): undefined reference to `tbb::interface9::global_control::internal_destroy()'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::invalid_argument@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::length_error::length_error(std::string const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::range_error::range_error(std::string const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_allocate_exception@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `std::bad_alloc::~bad_alloc()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::string::_Rep::_M_destroy(std::allocator<char> const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::bad_alloc::~bad_alloc()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_throw@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `std::string::_Rep::_M_dispose(std::allocator<char> const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `operator delete(void*)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::runtime_error::runtime_error(std::string const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::runtime_error::~runtime_error()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::length_error::~length_error()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::range_error::~range_error()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `operator new(unsigned long)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `vtable for __cxxabiv1::__ class_type_info@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_end_catch@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_rethrow@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::out_of_range@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::string::_Rep::_S_empty_rep_storage@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::invalid_argument::~invalid_argument()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::length_error@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_call_unexpected@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `__gxx_personality_v0@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `std::out_of_range::out_of_range(std::string const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_free_exception@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `operator delete[](void*)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::bad_alloc@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::range_error@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::exception::~exception()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::exception@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `typeinfo for std::runtime_error@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::out_of_range::~out_of_range()@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `vtable for __cxxabiv1::__ si_class_type_info@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_begin_catch@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `vtable for __cxxabiv1::__ vmi_class_type_info@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `operator new[](unsigned long)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `__cxa_pure_virtual@CXXABI_1.3'
/lib/../lib64/libtbb.so: undefined reference to `std::invalid_argument::invalid_argument(std::string const&)@GLIBCXX_3.4'
/lib/../lib64/libtbb.so: undefined reference to `vtable for std::bad_alloc@GLIBCXX_3.4'
collect2: error: ld returned 1 exit status
make: *** [examples/bernoulli/bernoulli] Error 1
rm examples/bernoulli/bernoulli.o examples/bernoulli/bernoulli.hpp

```

And for `make print-compiler-flags`

```no-highlight
 Current configuration:
  - OS (Operating System): Linux
  - CXX (Compiler): /opt/gridware/depots/e2b91392/el7/pkg/compilers/gcc/11.2.0/bin/g++
  - CXX_TYPE gcc
  - Compiler version: 11.2
  - O (Optimization Level): 3
  Library configuration:
  - EIGEN stan/lib/stan_math/lib/eigen_3.4.0
  - BOOST stan/lib/stan_math/lib/boost_1.84.0
  - SUNDIALS stan/lib/stan_math/lib/sundials_6.1.1
  - TBB stan/lib/stan_math/lib/tbb_2020.3
  - GTEST stan/lib/stan_math/lib/benchmark_1.5.1/googletest/googletest
  - STAN_THREADS                
  - STAN_OPENCL                 
  - STAN_MPI                    
  Compiler flags (each can be overriden separately):
  - CXXFLAGS_LANG -std=c++17
  - CXXFLAGS_WARNINGS -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess
  - CXXFLAGS_OPTIM              
  - CXXFLAGS_FLTO               
  - CXXFLAGS_BOOST              
  - CXXFLAGS_EIGEN              
  - CXXFLAGS_OS -pthread -D_REENTRANT
  - CXXFLAGS_GTEST              
  - CXXFLAGS_THREADS            
  - CXXFLAGS_OPENCL             
  - CXXFLAGS_TBB -I stan/lib/stan_math/lib/tbb_2020.3/include
  - CXXFLAGS_OPTIM_TBB          
  - CXXFLAGS_MPI                
  - CFLAGS_SUNDIALS             
  - CXXFLAGS_SUNDIALS -pipe
  - CXXFLAGS_OPTIM_SUNDIALS     
  LDLIBS:
  - LDLIBS_LANG                 
  - LDLIBS_WARNINGS             
  - LDLIBS_EIGEN                
  - LDLIBS_BOOST                
  - LDLIBS_SUNDIALS             
  - LDLIBS_OS                   
  - LDLIBS_GTEST                
  - LDLIBS_OPENCL               
  - LDLIBS_TBB -ltbb
  - LDLIBS_MPI                  
  LDFLAGS:
  - LDFLAGS_LANG                
  - LDFLAGS_WARNINGS            
  - LDFLAGS_EIGEN               
  - LDFLAGS_BOOST               
  - LDFLAGS_SUNDIALS            
  - LDFLAGS_OS                  
  - LDFLAGS_GTEST               
  - LDFLAGS_OPENCL              
  - LDFLAGS_TBB -Wl,-L,/mnt/data1/users/mcarter/cmdstan-2.36.0/stan/lib/stan_math/lib/tbb -Wl,-rpath,/mnt/data1/users/mcarter/cmdstan-2.36.0/stan/lib/stan_math/lib/tbb
  - LDFLAGS_MPI                 

```

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [January 28, 2025, 3:32pm UTC](https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618/7 "2025-01-28T15:32:51Z")

</div>

Ok, so it looks like LD is being passed `-L/lib/../lib64 `, which contains `libtbb.so`. I’m guessing this comes from either `LDLIBS` or `LDFLAGS` in your environment variables.

I _believe_ all you need to do is make sure that the TBB from CmdStan is listed _earlier_ in the list, so you might be able to get away with something like this in make/local

```makefile
CUSTOM_LDFLAGS = $(LDFLAGS_TBB) + $(LDFLAGS)
override LDFLAGS = $(CUSTOM_LDFLAGS)

```

---

<div class="post-metadata">

**Author:** ![stevebronder](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/stevebronder/32/17242_2.png) [@stevebronder](https://discourse.mc-stan.org/u/stevebronder)\
**Post date:** [January 28, 2025, 7:39pm UTC](https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618/8 "2025-01-28T19:39:16Z")

</div>

> [@mjcarter](#):
>
> Intel TBB is not installed as a package on the HPC system that I am using. A number of packages that ship with Intel TBB are available, but I have not loaded any of these (see below), so they shouldn’t change things in my environment.

As Brian said, from the error message from the compiler it looks like tbb is still loaded on your instance even if you are not directly loading it. Can you run `env` and look for `TBBROOT`? If that exists then you can use what brian posted above.

```make
TBB_CXX_TYPE=gcc
TBB_INTERFACE_NEW=true
TBB_INC=$(TBBROOT)/include/
TBB_LIB=$(TBBROOT)/lib/

```

If that does not work can you run `ls ../lib64` and look for `libtbb.so.2` (or just `libtbb.so`)? If that is there then you will also have to change the above to something like the below, where the include folder is usually in either `/include/` or `/include/tbb/{VERSION_NUMBER}` where {VERSION\_NUMBER} is something like `2021.01.12` etc.

```make
TBB_CXX_TYPE=gcc
TBB_INTERFACE_NEW=true
TBB_INC=/include/
TBB_LIB=/lib64/

```

If neither of those two work then you should contact your hpc admin as they will know where those are in your system and can give you the correct directories. For us it’s kind of whackamole without knowing what your systems directory structure looks like.

---

<div class="post-metadata">

**Author:** ![rdauria](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/rdauria/32/20951_2.png) [@rdauria](https://discourse.mc-stan.org/u/rdauria)\
**Post date:** [September 5, 2025, 5:33pm UTC](https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618/9 "2025-09-05T17:33:38Z")

</div>

I could not get pass the issue reported by @mjcarter, until I noticed that in the compilation of bernoulli `-ltbb` came before `stan/lib/stan_math/lib/tbb/libtbb.so.2` therefore selecting the tbb installed in the OS (if any), the full compilation instruction is:

`g++ -Wno-deprecated-declarations -std=c++17 -pthread -D_REENTRANT -Wno-sign-compare -Wno-ignored-attributes -Wno-class-memaccess -I stan/lib/stan_math/lib/tbb_2020.3/include -O3 -I src -I stan/src -I stan/lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.4.0 -I stan/lib/stan_math/lib/boost_1.84.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,“/u/home/systems/dauria/.cmdstan/cmdstan-2.36.0/stan/lib/stan_math/lib/tbb” -Wl,-rpath,“/u/home/systems/dauria/.cmdstan/cmdstan-2.36.0/stan/lib/stan_math/lib/tbb” examples/bernoulli/bernoulli.o src/cmdstan/main.o -ltbb 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.so.2 -o examples/bernoulli/bernoulli`

this seems to be caused by the following lines:

`LDLIBS_TBB ?= -ltbb`

in:

`stan/lib/stan_math/make/compiler_flags`

I thought I had opened a bug report on August 21 but I am unable to find it at the moment. In any events I think that removing the `LDLIBS_TBB` lines in `stan/lib/stan_math/make/compiler_flags` would solve the issue.

Thanks,

RD

---

<div class="post-metadata">

**Author:** ![rdauria](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/rdauria/32/20951_2.png) [@rdauria](https://discourse.mc-stan.org/u/rdauria)\
**Post date:** [September 5, 2025, 5:37pm UTC](https://discourse.mc-stan.org/t/cmdstan-intel-tbb-error-when-compiling-model/38618/10 "2025-09-05T17:37:12Z")

</div>

> [@rdauria](#):
>
> compiler\_flags

found the bug report: [Please remove LDLIBS\_TB from stan/lib/stan\_math/make/compiler\_flags · Issue #1329 · stan-dev/cmdstan · GitHub](https://github.com/stan-dev/cmdstan/issues/1329)
