skydoor
skydoor

Reputation: 41

Compiling boost::thread with Eclipse

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.

Upvotes: 2

Views: 2196

Answers (3)

Clickmit Wg
Clickmit Wg

Reputation: 553

To add a linker-> 1.right click on the project 2.select on the properties window 3.click on the c/c++ build 4. choose setting 5. and choose libraries 6. then u can add linkers: boost_thread and boost_system etc

Upvotes: 1

Alex
Alex

Reputation: 2361

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

Upvotes: 1

user229321
user229321

Reputation: 294

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

Upvotes: 4

Related Questions