Linux g++ 编译添加 pthread

If you are going to compile a C program with pthread.h in LINUX using GCC or G++ you will have to use –lpthread option after the compile command.

gcc xyz.c -o xyz -lpthread

Here,

gcc is compiler command (compiler name)

xyz.c is a source file name.

-o is an option to create objcect file.

xyz is the name of object (binary) file.

-lpthread is an option for pthread.h

for more details here is the link conatining complete article on it.

Compiling C program with pthread.h in Linux.

pthread库不是 Linux 默认的库,有些 Library 默认使用pthread但是在介绍的时候没有说明,导致编译时出错。-lpthread-pthread两种写法好像都可以。

posted @ 2019-03-11 21:03  2021年的顺遂平安君  阅读(1136)  评论(0编辑  收藏  举报