#include <boost/thread.hpp>
#include<iostream>
using namespace std;
using namespace boost;
using namespace boost::this_thread;
void fxn1() {
for (int i=0; i<10; ++i) {
cout << i << ") Do something in parallel with main method." << endl;
boost::this_thread::yield();
}}
int main() {
boost::thread t(&fxn1);
for (int i=0;i<10; i++) {
cout << i << ". Do something in main method." << endl;
}
return 0;
}
using
g++ boosttest1.c -o boosttest1
the compiler throws errors to each reference of a boost function (I have removed the names of temp files referenced by the compiler):
undefined reference to `boost::this_thread::yield()'
undefined reference to `boost::thread::~thread()'
In function `boost::detail::thread_data_base::thread_data_base()': undefined reference to `vtable for boost::detail::thread_data_base'
In function `boost::thread::thread<void (*)()>(void (*)(), boost::disable_if<boost::is_convertible<void (*&)(), boost::detail::thread_move_t<void (*)()> >, boost::thread::dummy*>::type)': undefined reference to `boost::thread::start_thread()'
etc. Please respond if the remainder of the messages are cogent.
If I comment out both lines with boost, the compile works perfectly, and if I comment out only the second, I receive:
In function `fxn1()':
boostthreadtest.c:(.text+0x43): undefined reference to `boost::this_thread::yield()'
collect2: ld returned 1 exit status
How do I reference the libraries correctly? It seems as though the more detailed thread.hpp files are correctly referenced and present, but are not being noticed by the compiler.
Thanks for your patience.
floobit