全部博文(135)
分类: LINUX
2010-10-25 09:26:19
In GCC, the -pthread (aka -pthreads) option manages both the compiler preprocessor /and/ linker to enable compilation with Posix threads. The preprocessor will define/enable/use Posix threads versions of some macros (or perform conditional compilation to enable Posix threads logic), and the linker will specifically link the resultant object against libpthread However, -lpthread simply tells the linker to attempt to resolve any external references against the libpthread library, in the same way that -lm tells the linker to attempt to resolve any external references against the libm library. For -lpthread, your code might not contain external references to libpthread, even if you wrote Posix thread code, because the critical macros haven't been switched on.