我试图在我的项目中遇到错误后,使用C++在Xcode(4.2)上运行一个小测试程序。Xcode上Boost的线程组
#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();
其中编译器o utputs错误,如:
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等其他函数,没有任何问题。但在尝试使用线程时遇到这些问题。
我需要:
- 指定我的 '其它链接器标记' 的标志吗?
- 重新安装boost还是某种?目前我正在使用Boost 1.49.0,使用自制软件安装(即sudo brew install boost)
或者是否还有其他需要包含的特定配置?
'boost_thread'需要显式链接。至于'BOOST_FOREACH',这是一个宏,并由预处理器扩展。 – chrisaycock 2012-07-23 17:04:34
@chrisaycock那么,即使我已经添加了-lboost_thread,它仍然会给出相同的错误。 – 2012-07-23 17:14:20