How to install TBB from source on Linux and make it work
Asked Answered
V

2

15

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.

Varini answered 23/5, 2012 at 19:25 Comment(4)
What did you try already? Is there any documentation for TBB? And most important: What is TBB? Can you be more specific?Zusman
@Zusman You can move your mouse over the tag and find out what TBB isCorrect
./configure; make; sudo make installMccusker
Worth noting that in Ubuntu 19.10, it all works after one sudo apt install: stackoverflow.com/questions/51031060/…Whydah
V
28

I have come with the solution. I'll post it here so it will help others with this topic.

  1. Download the latest stable source code and uncompress it, i.e in ~/tbbsrc

  2. Inside, type make. It should start compiling the tbb library and the memory allocators.

  3. The headers are in ~/tbbsrc/include

  4. 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.

  5. 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
  1. Let's try a simple example:
// 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;
}
  1. To compile, for example, with the release version:
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 find libtbb.so

  1. And that should work fine!

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++

Varini answered 26/5, 2012 at 19:27 Comment(7)
Yeah. Thats why you have to pass it with -Wl, so the linker "recognize it". This was tested both in Ubuntu and Windows with g++ 4.4 and g++ 4.7. I haven't tested it with newer versions.Varini
but isn't -W1 an option just providing info for warning? I did not write that option so I am curious... :)Eager
Or... wait it is not W1 but Wl... l as "linker"!!! Yeah! Understood!!! Sorry and thank you very muchEager
lol. It's tricky eh? I also have problems telling them apart :DVarini
When you're on Apple clang version 5.1, instead of typing make, type make compiler=clang or make compiler=clang stdlib=libc++.Teamster
@Teamster Thanks for the info. I'll update the answer accordingly.Varini
It's strange that make install isn't supported.Insinuation
S
11

https://github.com/wjakob/tbb seems to be the way to go.

git clone https://github.com/wjakob/tbb.git
cd tbb/build
cmake ..
make -j
sudo make install
Strom answered 2/6, 2019 at 14:27 Comment(3)
Thanks! Much easier than Intel's git distribution, which has no install. I suggest also running "make test" though, just in case.Vulgarism
This installed, but my runtime then expects to find libtbb.so.2 which is missing.Tangency
I fixed the missing file by adding the following line to /etc/ld.so.conf: /opt/intel/openvino_2021.1.110/deployment_tools/inference_engine/external/tbb/lib/ and then calling ldconfig.Tangency

© 2022 - 2024 — McMap. All rights reserved.