Boost logo

Boost Users :

From: Carl Wainwright (Carl.Wainwright_at_[hidden])
Date: 2007-05-08 12:56:23


Hi all,

I've started just recently to use boost in my C++ application to manage
some threads. However, when I link my application I get strange
undefined references

g++ -g -O -o test_exe -lcppunit -ldl -lpthread -lboost_thread Main.o
test.o
test.o(.text+0x874): In function `threadTestCases::spawnThread()':
: undefined reference to `boost::thread::thread(boost::function0<void,
std::allocator<boost::function_base> > const&)'
test.o(.text+0x8b7): In function `threadTestCases::spawnThread()':
: undefined reference to `boost::thread::join()'
test.o(.text+0x8ce): In function `threadTestCases::spawnThread()':
: undefined reference to `boost::thread::~thread()'
test.o(.text+0x8eb): In function `threadTestCases::spawnThread()':
: undefined reference to `boost::thread::~thread()'
collect2: ld returned 1 exit status
make: *** [test_exe] Error 1

As you can see I have linked in the boost_thread and pthread but still I
get the problem. My LD_LIBRARY_PATH is correctly setup to define the
path where boost is installed (/usr/lib/)

The code is as follows and is used in a CPPUNIT framework. The boost
code is in the spawnThread member function.

//---------------------------------------------------------------------
#include "test.h"
#include <ostream>
#include <pthread.h>

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

using namespace std;
using namespace boost;

CPPUNIT_TEST_SUITE_REGISTRATION( threadTestCases );

void threadTestCases::setUp()
{
   cout << "\nthreadTestCases::setUp\n" << endl ;
}

void threadTestCases::tearDown()
{
   cout << "\nthreadTestCases::tearDown\n" << endl ;
}

void threadTestCases::testThread()
{
   cout << "Thread [testThread] spawned\n" << endl;

   try
   {
      CPPUNIT_ASSERT(1 == 2);
      cout << "Thread end" << endl;
   }
   catch(...)
   {
      cout << "Exception caught in testThread, continue\n" << endl;
   }

   pthread_exit(0);
}

void *my_thread(void *)
{
   cout << "Thread [my_thread] spawned\n" << endl ;

   try
   {
      CPPUNIT_ASSERT(1 == 2);
   }
   catch(...)
   {
      cout << "Exception caught in my_thread, continue\n" << endl;
   }

   pthread_exit(0);
}

void threadTestCases::spawnThread()
{
pthread_t thread[2];
int ret;

   cout << "\nSpawning new thread\n" << endl;

   // Create thread via boost
   boost::thread mfThread(boost::bind(&threadTestCases::testThread,
this));

   // Start execution of thread
   mfThread.join();
}

Is there anything I have done wrong in the code or perhaps in the build
environment which is using Boost library v1.32.0-1 for Linux RedHat with
g++ (GCC 3.4.6)

Any help would be appreciated as this has been bugging me for several
hours today.

Cheers
Carl


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net