0

I am trying to build simple boost::thread example for test purpose. Other simple code compiled well using g++.

I checked other stackoverflow answers but it was not helpful for me.

Could someone help me out?

here is my code:

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

using namespace std;

class CThreadIO
{
  public:
    void TestThreadFirst()
    {
        while (true)
        {
            cout << "1 ";
            boost::this_thread::sleep(boost::posix_time::millisec(500));
        }
    }

    void TestThreadSecond(int num)
    {
        while (true)
        {
            cout << num << " ";
            boost::this_thread::sleep(boost::posix_time::millisec(500));
        }
    }
};

int main()
{
    CThreadIO io;

    boost::thread th1 = boost::thread(boost::bind(&CThreadIO::TestThreadFirst, &io));
    boost::thread th2 = boost::thread(boost::bind(&CThreadIO::TestThreadSecond, &io, 2));

    th1.join();
    th2.join();

    return 0;
}

Error messages:

$ g++ thread.cpp
Undefined symbols for architecture x86_64:
  "boost::this_thread::interruption_point()", referenced from:
      boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in thread-d302d6.o
....
....      
boost::_bi::list2<boost::_bi::value<CThreadIO*>, boost::_bi::value<int> > > > in thread-d302d6.o
      "vtable for boost::detail::thread_data_base", referenced from:
          boost::detail::thread_data_base::thread_data_base() in thread-d302d6.o
      NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
MJK
  • 189
  • 1
  • 3

0 Answers0