gcc compiling threaded programs need to bring -lpthread option (otherwise error: undefined reference to `pthread_create ')

Pthread_create program uses two functions, includes the header files #include <pthread.h>.

gcc xxx.c -o xxx

The following error when compiling:

 

 

 

analysis:

Usually you need to add additional options when using gcc compiler uses POSIX thread of the program to link to the library.

Direct plus -lpthread options here.

gcc xxx.c -o xxx -lpthread

Compile
----------------
and original article is CSDN blogger "zhangjs0322", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link: Copyright this statement.
Original link: https: //blog.csdn.net/zhangjs0322/article/details/16341775

Guess you like

Origin www.cnblogs.com/renzmin/p/12096200.html