我想在我的代码中使用线程,并认为即将到来的C++0x扩展会很方便,因为它们最终会成为标准。这似乎是面向未来的,不需要使用像boost::thread这样的附加库。
不幸的是,我找不到有用的信息,关于目前gcc支持哪些关于线程的特性。我使用的是unique_locks,它似乎还不起作用。这是链接器的输出:
.build_debug/src/core/simulator.o: In function `Simulator::start(int, int, int, int)':
simulator.cpp:(.text+0x1fc): undefined reference to `_ZSt4lockISt11unique_lockISt5mutexES2_IEEvRT_RT0_DpRT1_'
.build_debug/src/core/simulator.o: In function `Simulator::resume()':
simulator.cpp:(.text+0x351): undefined reference to `_ZSt4lockISt11unique_lockISt5mutexES2_IEEvRT_RT0_DpRT1_'
.build_debug/src/core/simulator.o: In function `Simulator::pause()':
simulator.cpp:(.text+0x417): undefined reference to `_ZSt4lockISt11unique_lockISt5mutexES2_IEEvRT_RT0_DpRT1_'
.build_debug/src/core/simulator.o: In function `Simulator::stop()':
simulator.cpp:(.text+0x4cd): undefined reference to `_ZSt4lockISt11unique_lockISt5mutexES2_IEEvRT_RT0_DpRT1_'有没有人理解这些信息?我猜他们指的是unique_locks的用法。但是为什么会发生这些错误呢?
我的源代码类似于下面的代码:
std::unique_lock<std::mutex> lkIntra(intraMtx, std::defer_lock); std::unique_lock<std::mutex> lkInter(interMtx, std::defer_lock); std::lock(lkIntra, lkInter);
编辑:我试着用gcc 4.3.X和4.4.5编译了这个。连接子是g++ 4.3、4.4和4.5。
EDIT2:我只是尝试使用std-thread的boost等效项。在添加编译器标志"-lboost_thread“之后,编译就可以工作了。如果没有它,链接过程会导致类似的错误消息。现在我在想,在使用标准线程时,我是否需要做一些类似的事情(我已经尝试过"-lpthread")。
发布于 2010-12-31 21:07:54
当前的G++开发版本支持它:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00729.html
4.5.1版本似乎不支持(至少对我来说,在Mac OS Intel上是这样)。
https://stackoverflow.com/questions/4454121
复制相似问题