views:

70

answers:

2

I have a simple program which creates and executes as thread using boost threads in c++.

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


void hello()
{

    std::cout<<"Hello, i am a thread"<<std::endl;

}

int main()
{
    boost::thread th1(&hello);
    th1.join();


}

The compiler throws an error against the th1.join() line. It says "
Multiple markers at this line

- undefined reference to 

 `boost::thread::join()'

- undefined reference to 

 `boost::thread::~thread()'

"

+1  A: 

It's definitely the problem of not including appropriate headers / linking libs.

1) You should check your include path for having appropriate boost folder and boost headers. 2) You should build your application with appropriate static libraries (xxx.lib) files. For boost::thread that file would be named something like libboost_thread_xxx.lib

Kotti
A: 

In Eclipse, right-click on your project and go to Properties.

Goto C/C++ Build -> settings -> tool settings

Next, open the Libraries section under GCC C++ Linker.

In the Libraries (-l) panel add an entry with the value boost_thread.

(I'm assuming your using Linux, if not check out This question)

Flamewires
Thanks, but I am using a windows machine. I tried doing the dame for windows and it cannot link correctly to the file. I am trying to read the entire article pointed out by your link but it seems too verbose..
Eternal Learner
how did you install boost then? did you build it from source?
Flamewires