(.text+0x57): undefined reference to `pthread_create'求解
废话不多说,程序如下:
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
void *myThread( void *arg )
{
pthread_t pt;
pt = pthread_self();
printf("Thread %x ran!\n", (int)pt );
pthread_exit( NULL );
}
int main()
{
int ret;
pthread_t mythread;
ret = pthread_create( &mythread, NULL, myThread, NULL );
if (ret != 0) {
printf( "Can't create pthread (%s)\n", strerror( errno ) );
exit(-1);
}
return 0;
}
编译:
gcc ptcreate.c -o create
/tmp/cc1UwArn.o: In function `main':
ptcreate.c:(.text+0x57): undefined reference to `pthread_create'
collect2: ld returned 1 exit status
请问各问问题出在哪里,该如何解决,谢谢~~~
------解决方案--------------------
gcc ptcreate.c -o create -lpthread