I wanted to use threads in my code and thought that the upcoming C++0x extensions would be handy as they will become a standard eventually. This seemed to be future-proof without the need to use additional libraries like the boost::thread.
Unfortunately I couldn’t find useful information about which features regarding threads are currently supported by gcc. I’m using unique_locks which seem not to work, yet. This is the output of the linker:
.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_'
Does anybody understand these messages? I guess they are referring to the usage of unique_locks. But why do these errors occur?
My source code resembles this one:
std::unique_lock<std::mutex> lkIntra(intraMtx, std::defer_lock);
std::unique_lock<std::mutex> lkInter(interMtx, std::defer_lock);
std::lock(lkIntra, lkInter);
EDIT: I tried to compile this with gcc 4.3.X and 4.4.5. The linker was g++ 4.3, 4.4 and 4.5.
EDIT2: I just tried to use the boost equivalents to the std-threads. After adding the compiler flag “-lboost_thread” the compilation worked. Without which the linking process resulted in similar error messages. Now I’m wondering whether I need to do something alike when using standard threads (I already tried “-lpthread”).
The current development version of G++ supports it: http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00729.html
The 4.5.1 version doesn’t seem to (at least, for me on Mac OS Intel).