I would like to know how to install TBB from source and make it work on a Linux system. I have had some problems when it comes using it, problems that don't appear if I install TBB via the package manager.
In the TBB webpage, there are some guidelines on how about to do this, like setting the LD_LIBRARY_PATH
and CPATH
variables, or sourcing the tbbvars.sh
file. Even if I do that, when I try to compile an example g++
says that tbb
is not found.
So my question is, is there an easy way to setup everything (compile the source code, what variables should I set...) in order to use TBB?
Thanks.
NOTE: The library version number when this question was asked was 2 (if I recall correctly). I have personally tested the solution up to version 4.1, but I think it should work too for current version 4.2 (update 3)
since the building method remains the same.
Threading Building Blocks (TBB) is a C++ runtime library that abstracts the low-level threading details necessary for optimal multi-core performance. It uses common C++ templates and coding style to eliminate tedious threading implementation work.
oneAPI Threading Building Blocks (oneTBB; formerly Threading Building Blocks or TBB), is a C++ template library developed by Intel for parallel programming on multi-core processors. Using TBB, a computation is broken down into tasks that can run in parallel.
I have come with the solution. I'll post it here so it will help others with this topic.
Download the latest stable source code and uncompress it, i.e in ~/tbbsrc
Inside, type make
. It should start compiling the tbb library and the memory allocators.
The headers are in ~/tbbsrc/include
Inside ~/tbbsrc/build
will be two new folders, one for the release version and the other for the debug version. Those folders are named like architecture_ldVersion_g++Version_kernelVersion
.
I recommend setting some variables, for example in your ~/.bashrc
file, like:
TBB_INSTALL_DIR = $HOME/tbbsrc
TBB_INCLUDE = $TBB_INSTALL_DIR/include
TBB_LIBRARY_RELEASE = $TBB_INSTALL_DIR/build/RELEASE_FOLDER
TBB_LIBRARY_DEBUG = $TBB_INSTALL_DIR/build/DEBUG_FOLDER
// main.cpp
#include "tbb/task_scheduler_init.h"
int main(int argc, char* argv[]) {
// tbb::task_scheduler_init init(tbb::task_scheduler_init::automatic);
// implicit tbb::task_sheduler_init::automatic
tbb::task_scheduler_init init;
return 0;
}
g++ main.cpp -I$TBB_INCLUDE -Wl,-rpath,$TBB_LIBRARY_RELEASE -L$TBB_LIBRARY_RELEASE -ltbb
Note: with
-Wl,-rpath,$TBB_LIBRARY_RELEASE
, we are telling the dynamic linker where to findlibtbb.so
Best regards!
Installation for Apple clang 5.1: [thanks to rwols for the info]
Instead of typing make
, type make compiler=clang
or make compiler=clang stdlib=libc++
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With