6

What are the compiler/linker requirements for using pthread library with clang in OS X.

With GCC i know that using -pthread set the appropriate compiler/linker options, but i unsure about OS X with 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 
José
  • 3,041
  • 8
  • 37
  • 58

1 Answers1

13

clang requires -pthread when compiling but not when linking. This is annoying, but it is observed behavior:

$ 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
$
vy32
  • 28,461
  • 37
  • 122
  • 246
  • Does compiling and linking simultaneously emit a warning with/without `-pthread`? (`clang -o x x.cpp`, I think) That's the one combination you don't try in your answer. (I don't have easy access to a Mac, but am trying to develop for one...) – Jason Gross Jan 02 '16 at 02:58