简体   繁体   English

在linux机器上编译线程程序时,它给出“ undefined reference”错误

[英]while compiling thread program on linux machine it gives “undefined reference ” error

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

Are you compiling it as 'gcc -lpthread fileName.c' 您是否将其编译为“ gcc -lpthread fileName.c”

You will have to include the header file pthread.h 您将必须包含头文件pthread.h

#include <pthread.h>

and when compiling, specify the library to link with using ' -l 'option of gcc. 并且在编译时,使用gcc的-l选项指定要链接的库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM