8

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.

d3pd
  • 7,935
  • 24
  • 76
  • 127
  • Specify -L option with path to libtbb.so.2 binaries – Anton Sep 02 '14 at 06:37
  • 3
    that's easy. linker works in one pass and in order of the command-line arguments. Thus at the step when you specified a library, the linker found no dependencies to it and discarded as unused – Anton Sep 05 '14 at 17:01
  • 2
    possible duplicate of [Linker order - GCC](http://stackoverflow.com/questions/45135/linker-order-gcc) – Alexey Kukanov Oct 03 '14 at 13:02

0 Answers0