我正在嘗試一些C++ 11線程支持,但是我面臨的瓶頸是瓶頸。我使用由rubenvb構建的gcc 4.8.0(直接從sourceforge下載)[x86_64-w64-mingw32-gcc-4.8.0-win64_rubenvb],並發現它似乎不支持C++ 11線程功能。以下代碼未能編譯並投訴'thread' is not a member of 'std'
。隨着谷歌搜索,有一個4.7實驗(也由rubenvb)與std線程支持。由於我的主要項目的一部分需要4.8版本的其他C++ 11功能,所以我沒有試用4.7版本。請幫助澄清我下載的工具鏈是否啓用線程。'thread'不是GCC的'std'的成員4.8
平臺:窗口64,Qt的4.8
- 作爲Qt的libaries從源代碼構建,改變工具鏈將意味着重新編譯整個(用gcc工具鏈下載從源構建)庫集,這聽起來不好。這兩個文件或gcc中是否有任何遺漏?謝謝。
更新:剛纔下載的實驗4.8版[x86_64的-W64-的mingw32-GCC-4.8-stdthread-win64_rubenvb]和編譯測試代碼。所以現在的問題是
「'實驗'版本是否安全使用?」
測試代碼中使用
#include <iostream>
#include <thread>
#include <mutex> // try other c++11 threading feature
void doSomeWork(void) { std::cout << "hello from thread..." << std::endl; }
int main() {
std::mutex m; // also fail here
std::thread t(doSomeWork);
t.join();
return 0;
}
和Makefile中
CC := g++
SRC := test$(BUILD).cpp
OBJ := $(SRC:.cpp=.o)
BIN := test$(BUILD).exe
CXXFLAGS := -std=c++0x -Wall -Wextra -O0 -ggdb -lpthread -mthreads -pthread -Wno-unknown-pragmas
clean : ; del /a/s $(BIN) $(OBJ)
all : $(BIN) ; del $(OBJ)
$(BIN) : $(OBJ) ; $(CC) $(CXXFLAGS) $^ -o [email protected]
%.o : %.cpp ; $(CC) -c $(CXXFLAGS) $< -o [email protected]
.PHONY: clean all
你可以在命令行試試? 'g ++ -std = C++ 0x -Wall -Wextra -O0 -ggdb -lpthread -mthreads -pthread -Wno-unknown-pragmas test $ {BUILD} .cpp'? – juanchopanza 2014-09-20 18:01:05
試過了,不行。 – 2014-09-21 02:24:18