有以下程序:
void *thread(void *vargp);
int main() {
pthread_t tid;
pthread_create(&tid, NULL, thread, NULL);
exit(0);
}
/* thread routine */
void *thread(void *vargp) {
sleep(1);
printf("Hello, world!\n");
return NULL;
}
我应该纠正它。我已经添加了左侧的包含:
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
但我仍然收到以下错误:
/tmp/ccHwCS8c.o: In function `main':
1.c:(.text+0x29): undefined reference to `pthread_create'
collect2: ld returned output state 1
我尝试像答案所说的那样在编译器中添加-lpthread,但我仍然得到这个错误代码:
@lap:~$ gcc -Wall -lpthread 1.c -o uno
/tmp/ccl19SMr.o: In function `main':
1.c:(.text+0x29): undefined reference to `pthread_create'
collect2: ld returned exit state 1