- 论坛徽章:
- 0
|
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
pthread_t ntid;
void printids(const char *s)
{
pid_t pid;
pthread_t tid;
pid=getpid();
tid=pthread_self();
printf("%s pid %u tid %u (0x%x)\n",s,(unsigned int)pid,
(unsigned int)tid,(unsigned int)tid);
}
void *thr_fn(void *arg)
{
printf("new thread: ");
return ((void *)0);
}
int main()
{
int err;
err=pthread_create(&ntid,NULL,thr_fn,NULL);
if(!err)printf("Can't create thread\n");
printids("main thread:");
sleep(1);
exit(0);
} |
gcc ./thread.c
/tmp/ccIkgqUq.o: In function `main':
thread.c .text+0x8a): undefined reference to `pthread_create'
collect2: ld returned 1 exit status
为什么? |
|