linux中的线程支持是由库完成的,你必须在链接过程中明确指名该库-lpthread

来源:互联网 发布:人工智能电影国语 编辑:程序博客网 时间:2024/06/06 16:57

刚开始学习多线程编程,输入的第一个例子程序就有问题,它编译是通过了,但是联接时就出问题: 
          thrdcreat.o(.text+0x21):   In   function   `main ': 
:   undefined   reference   to   `pthread_create ' 
thrdcreat.o(.text+0x5c):   In   function   `main ': 
:   undefined   reference   to   `pthread_create ' 
thrdcreat.o(.text+0x8f):   In   function   `main ': 
:   undefined   reference   to   `pthread_join ' 
thrdcreat.o(.text+0x9f):   In   function   `main ': 
:   undefined   reference   to   `pthread_join ' 
collect2:   ld   returned   1   exit   status 
请问,这是错在哪里?


由于linux中的线程支持是由库完成的,你必须在链接过程中明确指名该库 
例子 
gcc   -o   demo   -g   thread_demo.c   -lpthread

原创粉丝点击