I have a simple program which creates and executes as th开发者_JAVA技巧read 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()'
"
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
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)
精彩评论