Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

How to use tbb with gcc ?

christiecohen
Beginner
4,356 Views
I try to copy the lib and header files to gcc and write a simple test program, shown as below:

//############################
#include "tbb/task_scheduler_init.h"

using namespace tbb;

static const size_t N = 23;

int main() {
task_scheduler_init init;
return 0;
}
//############################


when I compiled it, with "gcc xxx.cpp", such errors were reported, shown as below:

//#############################
/tmp/ccWKfzHj.o: In function `tbb::task_scheduler_init::task_scheduler_init(int)':
compute_pi.cpp:(.text._ZN3tbb19task_scheduler_initC1Ei[tbb::task_scheduler_init::task_scheduler_init(int)]+0x28): undefined reference to `tbb::task_scheduler_init::initialize(int)'
/tmp/ccWKfzHj.o: In function `tbb::task_scheduler_init::~task_scheduler_init()':
compute_pi.cpp:(.text._ZN3tbb19task_scheduler_initD1Ev[tbb::task_scheduler_init::~task_scheduler_init()]+0x16): undefined reference to `tbb::task_scheduler_init::terminate()'
/tmp/ccWKfzHj.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
//#############################

Anybody can tell me how to deal with it?

Thanks in advance.
0 Kudos
3 Replies
TimP
Honored Contributor III
4,356 Views
First of all, you can't run C++ without C++ libraries, so you should be using g++ rather than gcc. You would also have to link tbb libraries,
for example by using the provided setup script to set the library path.
0 Kudos
christiecohen
Beginner
4,356 Views
Thanks.


I've changed to use g++ instead.

But the problem still happen.

I found that's because of this sentence "task_scheduler_init init;".

When I deleted it, everything became OK.


It seems the tbb lib didn't work, right?


I just copied the header file to /usr/lib/gcc/i486-linux-gnu/4.1/include,
and the lib files to /lib and /usr/lib and /usr/lib/gcc/i486-linux-gnu/4.1

Is this correct?
Or what should I do?

I didn't find any detailed instruction.


0 Kudos
ARCH_R_Intel
Employee
4,356 Views

The undefined references are defined by the TBB run-time library. To satisfy the references, you must link against libtbb.so or libtbb_debug.so run-time libraries.

To build the run-time libraries, go to the top-level directory of the TBB package and type "gmake". This will build the libraries. Do "ls build/*/*.so" to see where they were built. To link against one of the libraries, do one of the following:

  1. Put the library explicitly on the gcc command line.
  2. Or use the gcc options "-L(path)" and "-ltbb" [or -ltbb_debug] to specify the library directory and name respectively.
  3. Or use one of the "tbbvars.*" scripts to set your environment variables. For example, I'm a csh user, so I cd to the directory where the library was built and use "source tbbvars.csh" to set my environment variables.

- Arch

0 Kudos
Reply