1、gcc用于编译C程序,cpp程序需要用g++
2、因为pthread并非Linux系统的默认库,而是POSIX线程库。在Linux中将其作为一个库来使用,因此加上 -lpthread(或-pthread)以显式链接该库。
[ zjy@livedvd ~]$ gcc -o thread thread.c -pthread
[zjy@livedvd ~]$ gcc -o thread thread.c -lpthread
本文介绍了如何使用GCC编译C程序,并特别强调了编译带有多线程功能的程序时,需要链接POSIX线程库的方法。通过具体的命令行示例,展示了如何正确地指定-lpthread选项以确保程序能够正确链接到POSIX线程库。
1、gcc用于编译C程序,cpp程序需要用g++
2、因为pthread并非Linux系统的默认库,而是POSIX线程库。在Linux中将其作为一个库来使用,因此加上 -lpthread(或-pthread)以显式链接该库。
[ zjy@livedvd ~]$ gcc -o thread thread.c -pthread
[zjy@livedvd ~]$ gcc -o thread thread.c -lpthread
316
403
787

被折叠的 条评论
为什么被折叠?
