Reputation: 2936
I'm trying to learn Boost threading. I'm using code from a tutorial online, after some errors I realised that I needed a newer version of Boost so I downloaded the latest version of it into a directory, unzipped it and installed it with the commands:
./bootstrap.sh
./bjam install
The sample code I'm trying to run is this:
#include <boost/thread.hpp>
#include <iostream>
using namespace std;
using namespace boost;
void threader()
{
for (int i = 0; i < 5; ++i)
{
sleep(1);
cout << boost::this_thread::get_id() << "-" << i << endl;
//cout << "-" << i << endl;
}
}
int main()
{
thread t(threader);
sleep(1);
thread u(threader);
t.join();
u.join();
}
I compiled with the same line I used with the old version of Boost(1.33 as comes with Centos as standard):
g++ -Wall -L/usr/local/lib -lboost_thread threadtest.cpp -o threadtest
It compiled without error (unlike with the old version of Boost) but when I run threadtest I get:
./threadtest: error while loading shared libraries: libboost_thread.so.1.47.0: cannot open shared object file: No such file or directory
Looking into the /usr/local/lib dircetory I can see the following:
-rw-r--r-- 1 root root 217270 Nov 10 12:50 libboost_thread.a
lrwxrwxrwx 1 root root 25 Nov 10 12:43 libboost_thread.so -> libboost_thread.so.1.47.0
-rwxr-xr-x 1 root root 138719 Nov 10 12:43 libboost_thread.so.1.47.0
So I cannot see why it's not working. I think it's to do with the -lboost_thread part of the compilation line. I tried linking to the library directly with:
g++ -Wall -L/usr/local/lib libboost_thread.a threadtest.cpp -o threadtest
But it again can't find the file. Can anyone help with this?
Upvotes: 2
Views: 1338
Reputation: 2936
I needed to re-add the path of my lib directory to my LD_LIBRARY_PATH with the following:
export LD_LIBRARY_PATH="/usr/local/lib/"
That did the trick.
Upvotes: 2