how to get Threaded Building Blocks working in Ubuntu 14.04

d3pd picture d3pd · Sep 2, 2014 · Viewed 18.5k times · Source

I want to get TBB working, but I'm having a little difficulty getting the compiling to work on Ubuntu 14.04. I think it is likely a problem with setting the location of libraries for the compiler.

I installed TBB using the following command:

sudo apt-get install libtbb-dev

I have a small test example that I am now trying to compile. The code is as follows:

#include "tbb/task_scheduler_init.h"

int main(int argc, char* argv[]) {
    tbb::task_scheduler_init init;
    return 0;
}

The command I am running to compile this code is as follows:

g++ -std=c++11 -g -O2 -ltbb simple_test.cc -o simple_test

I am running this with G++ version 4.9.1. When I try to compile, I get the following errors:

/tmp/cc7Ls8Sb.o: In function `task_scheduler_init':
/usr/include/tbb/task_scheduler_init.h:126: undefined reference to `tbb::task_scheduler_init::initialize(int, unsigned long)'
/tmp/cc7Ls8Sb.o: In function `~task_scheduler_init':
/usr/include/tbb/task_scheduler_init.h:132: undefined reference to `tbb::task_scheduler_init::terminate()'
collect2: error: ld returned 1 exit status

The location of the file task_scheduler_init.h is /usr/include/tbb/task_scheduler_init.h.

Would you have any idea what I'm doing wrong?


EDIT: I reordered the arguments for g++ and this got it working:

g++ simple_test.cc -std=c++11 -g -O2 -ltbb -o simple_test

I don't really understand why this change has made the compiling successful.

Answer