0

I was trying to compile and link Intel's tbb into a simple program on my mac, but I keep getting an error saying that the library was linked properly.

dyld: Library not loaded: @rpath/libtbb.dylib
  Referenced from:<path>/./a.out
  Reason: image not found
Trace/BPT trap: 5

The test program I used has the following code

#include <iostream>
#include <cassert>

#include <tbb/concurrent_queue.h>

int main() {
    auto q = tbb::concurrent_queue<int>{};
    q.push(1);
    auto top_value = int{};
    assert(q.try_pop(top_value));
    assert(top_value == 1);
    assert(q.empty());

    return 0;
}

And this is how I built the library (with downloading the library included for your convenience)

curl -OL https://www.threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb2017_20170118oss_src.tgz
tar -xzvf tbb2017_20170118oss_src.tgz
mv tbb2017_20170118oss tbb
rm tbb2017_20170118oss_src.tgz
cd tbb
make tbb
mv build/*_release build/tbb_release

And I tried to compile the program with this command

g+++ another.cpp -I tbb/include -L tbb/build/tbb_release -ltbb -ldl

And then on running the program I get the error above. Any ideas on how I can go about fixing this?

My compiler's version is clang-800.0.42.1 and the operating system I am running is 10.11.5

Thanks!

Curious
  • 20,870
  • 8
  • 61
  • 146
  • 1
    Google up the -rpath linker option. – n. m. could be an AI Mar 07 '17 at 05:48
  • @n.m. I am not able to use the `-rpath` option.. clang complains saying that it is an unknown argument. I found https://gcc.gnu.org/ml/gcc-help/2005-12/msg00017.html and I am assuming I just have to include the path to the library the same way as I did for the `-L` flag – Curious Mar 07 '17 at 05:53
  • 1
    It's a linker option not a compiler option. You need to use -Wl,-rpath=xxxyyyzzz (read on -Wl, option). Btw use an absolute path. – n. m. could be an AI Mar 07 '17 at 06:25
  • @n.m. I still get an error from the linker, `ld: unknown option: -rpath=tbb/build/tbb_release`.. – Curious Mar 07 '17 at 13:53
  • Hmm. It looks like Apple ld works a bit differently from other flavours of ld. There is a slightly different syntax, and you may need to modify the library itself. Look here http://stackoverflow.com/questions/4513799/how-to-set-the-runtime-path-rpath-of-an-executable-with-gcc-under-mac-osx The idea is the same though, you set up rpath that says where to find libraries *at run time*. The -L option is only good to find libraries *at link time*. – n. m. could be an AI Mar 07 '17 at 14:08

0 Answers0