0

I keep getting this error message and don't know why.

dyld: Library not loaded: libboost_thread.dylib Referenced from: /Users/adhg/Documents/workspace_cpp/Boost_101/Release/Boost_101 Reason: image not found

the code:

#include <iostream>
#include <boost/thread.hpp>

void workerFunction() {
 boost::posix_time::seconds workTime(3);
 std::cout << "Worker: running" << std::endl;
 boost::this_thread::sleep(workTime);
 std::cout << "Worker: finished" << std::endl;
}

int main() {
 std::cout << "main: startup" << std::endl;
 boost::thread workerThread(workerFunction);
 std::cout << "main: waiting for thread" << std::endl;
 workerThread.join();
 std::cout << "main: done" << std::endl;
 return 0;
}

What I did is simply follow the instructions here and in many other places, the basics:

  1. download boost
  2. unzip to folder
  3. ./bootstrap.sh
  4. ./bjam

you will note that the usr/local/boost... is where I actually placed my folder (it exists) and under usr/local/boost_1_54_0/stage/lib I have the libboost_thread and so forth. Still...not sure why I get this error.

My settings looks like this now:

enter image description here

enter image description here

Can anyone point out what am I doing wrong?

adhg
  • 10,437
  • 12
  • 58
  • 94

1 Answers1

3

This looks to be a dynamic linking issue, and from a little research, it seems that this can be solved by setting the DYLD_LIBRARY_PATH environment variable to point to where the libraries are located (in your case, /usr/local/boost_1_54_0/stage/lib). You may wish to read this similar question and also this external page, the latter of which states

This happend because I built boost from source and kept it local. Thus the path to the library was not the default one. To solve this problem we have to edit the environment variable DYLD_LIBRARY_PATH, which is analogous to linux LD_LIBRARY_PATH

(Also, I'll just mention that if you are only interested in threading capabilities and not Boost as a whole, you could use C++11's <thread> header.)

Community
  • 1
  • 1
  • 1
    Hmm, odd. I am running out of ideas here! The only other thing I could suggest (if you didn't do it already) is to set the environment variable `DYLD_LIBRARY_PATH` in Eclipse directly. A guide that I stumbled upon (see [here](http://gordienoye.ca/words/?p=10)), also related to using Boost with Eclipse on Mac OS X, had the same problem you had, but solved it by using Eclipse's environment variable feature. It may be that Eclipse isn't properly getting the environment variable from your shell. Other than that, I'm not too sure. You may wish to try an Eclipse message board, too. –  Jul 07 '13 at 23:55
  • @user2530166 Nice, your last comment about the Eclipse EnvVars solved it for me – user695652 Apr 29 '14 at 02:54