I copied this example exactly from the boost library examples.
#include <boost/thread/thread.hpp>
#include <boost/thread/xtime.hpp>
#include <iostream>
struct thread_alarm
{
thread_alarm(int secs) : m_secs(secs) { }
void operator()()
{
boost::xtime xt;
boost::xtime_get(&xt, boost::TIME_UTC);
xt.sec += m_secs;
boost::thread::sleep(xt);
std::cout << "alarm sounded..." << std::endl;
}
int m_secs;
};
int main(int argc, char* argv[])
{
int secs = 5;
std::cout << "setting alarm for 5 seconds..." << std::endl;
thread_alarm alarm(secs);
boost::thread thrd(alarm);
thrd.join();
}
I still get the error
undefined reference to boost::thread::join();
Anyone help me out?
It sounds like you aren't linking against the boost::thread library. boost::thread is not a header-only library.
It works for me ,you need to link it to proper lib files libboost_thread-vc80-mt-gd-1_44.lib and
libboost_date_time-vc80-mt-gd-1_44.lib.