2010-12-15 77 views
4


我想在我的代碼中使用線程,並認爲即將推出的C++ 0x擴展將會很方便,因爲它們最終將成爲標準。這似乎是未來的證明,無需使用像boost :: thread這樣的額外庫。
不幸的是,我找不到有關線程當前哪些功能被gcc支持的有用信息。我正在使用unique_locks,但似乎還沒有工作。這是連接器的輸出: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。

編輯2:我只是試圖使用std線程的提升等價物。在添加編譯器標誌「-lboost_thread」後編譯工作。沒有它,鏈接過程導致類似的錯誤消息。現在我想知道在使用標準線程時是否需要做類似的事情(我已經嘗試過「-lpthread」)。

+0

您正在使用哪個gcc版本,並且您是使用g ++而不是gcc鏈接的? – nos 2010-12-15 21:23:58

+0

@nos請看看我的編輯。 – Bastian 2010-12-16 08:52:50

回答