由于pthread库不是Linux系统默认的库,连接时需要使用库libpthread.a
所以,
在gcc编译的使用应该加上 -pthread 选项 (注意不是 -lpthread)
eg:gcc thread.c -pthread -o thread
本文介绍在使用GCC编译时如何正确链接pthread库。由于pthread并非Linux系统默认加载的库,因此在编译时需指定-pthread选项而非-lpthread。示例命令:gcc thread.c -pthread -o thread。
由于pthread库不是Linux系统默认的库,连接时需要使用库libpthread.a
所以,
在gcc编译的使用应该加上 -pthread 选项 (注意不是 -lpthread)
eg:gcc thread.c -pthread -o thread