Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

trouble linking INTEL tbb library

Tags:

c++

linux

gcc

tbb

I read these threads:

Getting Thread Building Blocks (Intel TBB) running on Linux with gcc

unable to link Intel TBB library with libtbb in /usr/lib

g++ can't find headers even when it's specified

g++ cannot find header file

g++ can't find headers but I did include them

but still get this error:

   piCalc.cpp:8:17: fatal error: ttb.h: No such file or directory
 #include "ttb.h"

My code to calculate pi starts with

#include <iostream>
#include "ttb.h"
#include "parallel_for.h"

Running Ubuntu 14.04 with nvidia and cuda installed. To install TBB, I started with :

sudo apt-get install libtbb-dev

and it said

Reading package lists... Done
Building dependency tree       
Reading state information... Done
libtbb-dev is already the newest version.
The following package was automatically installed and is no longer required:
  libxine2-bin
Use 'apt-get autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

So I thought I was good to go. So, I tried:

g++ piCalc.cpp -ltbb -o pi 

and get the error. So I downloaded the archive from intel and decompressed it to my home directory into a directory named tbb.

Issuing ls gives:

CHANGES  COPYING  README  bin  doc  examples  include  index.html  lib  piCalc.cpp

Notice piCalc.cpp is in the tbb directory. Also, tbb.h is located at /include/tbb So I changed the include statements to

#include <iostream>
#include "/include/tbb/ttb.h"
#include "/include/tbb/parallel_for.h"

libtbb.so and libtbb.so.2 are located at lib/intel64/gcc4.4

My terminal command was issued thusly:

g++ piCalc.cpp  -o pi -I include/tbb -L lib/intel64/gcc4.4 -ltbb

as well as

g++ piCalc.cpp  -o pi -I include/tbb/ -L lib/intel64/gcc4.4/ -ltbb

as well as

g++ piCalc.cpp  -o pi -I /include/tbb -L /lib/intel64/gcc4.4 -ltbb

and the same error occurs

piCalc.cpp:8:30: fatal error: /include/tbb/ttb.h: No such file or directory
 #include "/include/tbb/ttb.h"

I tried absolute paths with this:

g++ piCalc.cpp -I /home/stefan/tbb/include/tbb -L /home/stefan/tbb/lib/intel64/gcc4.4 -ltbb -o pi

Still same error.

I tried changing my code to:

#include <iostream>
#include </home/stefan/tbb/include/tbb/ttb.h>
#include </home/stefan/tbb/include/tbb/parallel_for.h>

and get this:

stefan@HN5:~/tbb$ g++ piCalc3.cpp -I /home/stefan/tbb/include/tbb -L /home/stefan/tbb/lib/intel64/gcc4.4 -ltbb -o pi
piCalc3.cpp:8:46: fatal error: /home/stefan/tbb/include/tbb/ttb.h: No such file or directory
 #include </home/stefan/tbb/include/tbb/ttb.h>
                                              ^
compilation terminated.

Basically the same error but more verbose since I used the absolute path in the terminal command.

I thought maybe the LD_LIBRARY_PATH variable was important. CUDA messes with the LD_LIBRARY_PATH variable so I exported the intel libs and now printenv shows:

LD_LIBRARY_PATH=/home/stefan/tbb/lib/intel64/gcc4.4:/usr/local/cuda-7.5/lib64:

still getting the error.

Here is the verbose error:

stefan@HN5:~/tbb$ g++ piCalc.cpp -o pi -v -I/home/stefan/tbb/include/tbb -L/home/stefan/tbb/lib/intel64/gcc4.4 -ltbb 
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.4-2ubuntu1~14.04.1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1) 
COLLECT_GCC_OPTIONS='-o' 'pi' '-v' '-I' '/home/stefan/tbb/include/tbb' '-L/home/stefan/tbb/lib/intel64/gcc4.4' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.8/cc1plus -quiet -v -I /home/stefan/tbb/include/tbb -imultiarch x86_64-linux-gnu -D_GNU_SOURCE piCalc.cpp -quiet -dumpbase piCalc.cpp -mtune=generic -march=x86-64 -auxbase piCalc -version -fstack-protector -Wformat -Wformat-security -o /tmp/ccHq7bTl.s
GNU C++ (Ubuntu 4.8.4-2ubuntu1~14.04.1) version 4.8.4 (x86_64-linux-gnu)
    compiled by GNU C version 4.8.4, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/4.8"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/stefan/tbb/include/tbb
 /usr/include/c++/4.8
 /usr/include/x86_64-linux-gnu/c++/4.8
 /usr/include/c++/4.8/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++ (Ubuntu 4.8.4-2ubuntu1~14.04.1) version 4.8.4 (x86_64-linux-gnu)
    compiled by GNU C version 4.8.4, GMP version 5.1.3, MPFR version 3.1.2-p3, MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 83f8d9bb238019ed17000f1b7e141e5a
piCalc.cpp:8:30: fatal error: /include/tbb/ttb.h: No such file or directory
 #include "/include/tbb/ttb.h"
                              ^
compilation terminated.

I also get this error if I copy the include/tbb folder which has all the .h files into the /usr/local/include folder. I also tried brackets instead of quote for the include files in the source.

Since my brain is in a deep rut by now, I am hoping someone can help me by pointing out what I am missing.

like image 488
aquagremlin Avatar asked Oct 18 '22 11:10

aquagremlin


1 Answers

FINALLY, I figured it out so I am posting here so anyone else might benefit.

  1. Download the Intel libraries from here
  2. Extract the folder and rename it to tbb
  3. Move that folder into /usr/local
  4. In source use: #include <tbb/tbb.h>
  5. g++ test.cpp -o program -ltbb
like image 133
aquagremlin Avatar answered Oct 21 '22 05:10

aquagremlin