I was trying to run a small test program on Xcode (4.2) using C++ after encountering error in my project.
#include <boost/thread.hpp>
#include <boost/bind.hpp>
int main (int argc, const char * argv[])
{
boost::thread_group tg;
return 0;
}
But the whole program fails to build, outputting error:
Undefined symbols for architecture x86_64:
"boost::thread::~thread()", referenced from:
boost::thread_group::~thread_group()in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Then I tried using
thread_group * tg = new thread_group();
which compiles without issue, up until I tried to invoke
tg->join_all();
where the compiler outputs errors such as:
Undefined symbols for architecture x86_64:
"boost::detail::get_current_thread_data()", referenced from:
boost::detail::interruption_checker::interruption_checker(_opaque_pthread_mutex_t*, _opaque_pthread_cond_t*)in main.o
"boost::this_thread::interruption_point()", referenced from:
boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in main.o
"boost::this_thread::disable_interruption::disable_interruption()", referenced from:
boost::shared_mutex::lock_shared() in main.o
"boost::this_thread::disable_interruption::~disable_interruption()", referenced from:
boost::shared_mutex::lock_shared() in main.o
"boost::thread::join()", referenced from:
boost::thread_group::join_all() in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Does anyone know how to resolve these issues ? I've been using other functions such as BOOST_FOREACH without any issues. But encounter these while trying to use threads.
Do I need to:
- Specify flags on my 'Other Linker Flags'?
- reinstall boost or some sort ? Currently I am using Boost 1.49.0, installed using homebrew (i.e. sudo brew install boost)
Or are there any other specific configurations that I need to to include ?
The boost thread library has an actual library object you need to link against (
-lboost_thread
or sometimes-lboost_thread-mt
).