在OS X中使用带有clang的pthread库有什么编译器/链接器要求.
使用GCC我知道使用-pthread设置适当的编译器/链接器选项,但我不确定OS X与clang.
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
解决方法
clang在编译时需要-pthread,但在链接时不需要.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 $