编译时,-pthread and -lpthread的区别 Posted on 2015-05-14 Edited on 2021-06-27 In linux Disqus: gcc编译多线程代码时,参数不同导致结果的不同。 -pthread告诉编译器,要链接到pthread库,同时配置线程的编译。 下面的例子就显示了在使用-pthread时,定义了不同的宏。 1234567$ gcc -pthread -E -dM test.c > dm.pthread.txt$ gcc -E -dM test.c > dm.nopthread.txt$ diff dm.pthread.txt dm.nopthread.txt152d151< #define _REENTRANT 1208d206< #define __USE_REENTRANT 1 -lpthread只会告诉编译器,要链接到pthread库,但是这些宏不会被定义。 编译时,应该使用-pthread。 reference difference-between-pthread-and-lpthread-while-compiling