tags:

views:

297

answers:

2

I am using Ubuntu + Eclipse and installed boost(not sure correct). I installed Boost using apt-get install libboost*

I tested some simple code, it seems the boost working right.

However, when I try to learn the thread part, the code below does not work.

#include <boost/thread/thread.hpp> 
#include <iostream>
using namespace std;

void hello()
{
   cout<<"hello!"<<endl;
}   

int main()
{
    boost::thread thrd(&hello);
    cout<<"Just a test!"<<endl;
}

The error information is as follow, there are 4 errors.

Severity and Description Path Resource Location Creation Time Id
/usr/local/include/boost/thread/detail/thread.hpp undefined reference to `boost::detail::thread_data_base::~thread_data_base()'  FirstCppProject line 40 1260656497961 200


Severity and Description Path Resource Location Creation Time Id
/usr/local/include/boost/thread/detail/thread.hpp undefined reference to `boost::thread::start_thread()'  FirstCppProject line 191 1260656497967 202


Severity and Description Path Resource Location Creation Time Id
/usr/local/include/boost/thread/pthread/thread_data.hpp undefined reference to `vtable for boost::detail::thread_data_base'  FirstCppProject line 65 1260656497965 201


Severity and Description Path Resource Location Creation Time Id
undefined reference to `boost::thread::~thread()' FirstCppProject test.cpp line 15 1260656497959 199

Please forgive me if my question is too naive. Please offer any information you think might help me out.

+4  A: 

you have to link against the thread library libboost_thread_...

thanks for your quick comment. Is this a problem with Eclipse? So how to do that in Eclipse? I thought when I installed boost on Ubuntu, I don't have to anything with Eclipse.
skydoor
No, it's not an eclipse problem, you'll have to specify an option for the linker (check the project options), something like -lboost_thread-gcc-4.3 or similar, you'll have to find the library first to figure out its name, you'll most likely have to link against pthread as well.
You will have to link against pthread. I've had to do this before.
KitsuneYMG
+1  A: 

With Boost sometimes you just need to tell your linked where the libraries are and it will figure out which one to link against.

Alex
auto-linking doesn't work in g++, it's a visual c++ feature so it's not available under *nix