Undefined reference to pthread_create in Linux

后端 未结 14 2318
梦毁少年i
梦毁少年i 2020-11-22 03:18

I picked up the following demo off the web from https://computing.llnl.gov/tutorials/pthreads/

#include 
#include 
#define NU         


        
14条回答
  •  有刺的猬
    2020-11-22 03:53

    Both answers to this question so far are incorrect.
    For Linux the correct command is:

    gcc -pthread -o term term.c
    

    In general, libraries should follow sources and objects on command line, and -lpthread is not an "option", it's a library specification. On a system with only libpthread.a installed,

    gcc -lpthread ...
    

    will fail to link.

提交回复
热议问题