【问题标题】:while compiling thread program on linux machine it gives "undefined reference " error在 linux 机器上编译线程程序时,它给出“未定义的引用”错误
【发布时间】:2013-03-10 22:41:31
【问题描述】:

嗨,我在线程中编写了一个简单的程序来创建 10 个线程并正常执行它们,但是当我在 linux 机器上编译代码时,它会出现以下错误.. */tmp/cc4swqyK.o:在函数main': threadcreate1.c:(.text+0x40): undefined reference topthread_create' threadcreate1.c:(.text+0x78): undefined reference to `pthread_join' collect2: ld 返回 1 个退出状态*

【问题讨论】:

    标签: linux gcc pthreads


    【解决方案1】:

    你是编译成'gcc -lpthread fileName.c'

    您必须包含头文件 pthread.h

    #include <pthread.h>
    

    并且在编译时,使用 gcc 的 '-l' 选项指定要链接的库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-29
      • 1970-01-01
      • 2015-03-07
      • 2015-01-08
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      • 2015-07-11
      相关资源
      最近更新 更多