我在项目中遇到错误后,尝试使用C ++在Xcode(4.2)上运行一个小型测试程序。
#include <boost/thread.hpp>
#include <boost/bind.hpp>
int main (int argc, const char * argv[])
{
boost::thread_group tg;
return 0;
}
但整个程序无法构建,输出错误:
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
然后我尝试使用
thread_group * tg = new thread_group();
在没有问题的情况下编译,直到我尝试调用
tg->join_all();
编译器输出错误,例如:
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
有谁知道如何解决这些问题?我一直在使用其他功能,如BOOST_FOREACH,没有任何问题。但在尝试使用线程时遇到这些。
我需要:
或者我需要包含哪些其他特定配置?
答案 0 :(得分:4)
boost线程库有一个您需要链接的实际库对象(-lboost_thread
或有时-lboost_thread-mt
)。