2013-07-24 49 views
5

哪些是在OS X中使用並行線程庫鐺GCC的我都知道,使用-pthread設置相應的編譯器/連接器選項OS X鐺-pthread

編譯器/連接器的要求,但我不確定OS X與鐺。

air:~ jose$ clang++ -c test.cpp -pthread 
air:~ jose$ clang++ -o test -pthread test.o 
clang: warning: argument unused during compilation: '-pthread' 

air:~ jose$ g++ -c test.cpp -pthread 
air:~ jose$ g++ -o test -pthread test.o 
+0

應該完全一樣 - 我很確定。 –

+0

http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang – DrYap

+0

看到我剛添加的示例,似乎叮噹連接可執行文件時不需要-pthread。 –

回答

12

鐺當編譯時需要-pthread但鏈接時不需要。這很煩人,但它是觀察到的行爲:

$ clang -c x.cpp 
$ clang -pthread -c x.cpp 
$ clang -o x x.o 
$ clang -pthread -o x x.o 
clang: warning: argument unused during compilation: '-pthread' 
$ 

$ clang --version 
Apple LLVM version 5.0 (clang-500.2.76) (based on LLVM 3.3svn) 
Target: x86_64-apple-darwin13.0.0 
Thread model: posix 
$ 
+0

編譯和鏈接是否同時發出帶/不帶'-pthread'的警告? ('clang -o x x.cpp',我想)這是你在答案中不會嘗試的組合。 (我沒有方便地訪問Mac,但正在嘗試開發一個...) –

+0

號。clang -pthread -o x x.cpp不會發出警告。 – bjori

+0

不再... – vy32

0

我想我用來添加一個-lpthread到鐺了。

+0

如果你解釋這個關鍵的含義以及它如何解決問題會更好 –