Chinaunix

标题: 初学者。大家帮忙了,pthread_create 调用失败 [打印本页]

作者: hxdhxd_hxd    时间: 2005-03-10 09:58
标题: 初学者。大家帮忙了,pthread_create 调用失败
//test.c
void * start_routine(void *);
int main()
{
   pthread_t  tid;
  if (pthread_create(&tid,NULL,start_routine,NULL))
  {
     perror("create thread error";
     exit(1);
  }
  return ;
}
void * start_routine(void *arg)
{
   sleep(1000);
}
$gcc - test.c -o test

$test
  create thread error
gdb跟踪pthread_create返回值为-1
我想问一下  gcc - test.c -o test (-pthread) 必须加吗

谢谢各位请指教
作者: sjj1113    时间: 2005-03-10 13:13
标题: 初学者。大家帮忙了,pthread_create 调用失败
gcc -o file file.c -lpthread


将libpthread link进来
作者: hxdhxd_hxd    时间: 2005-03-10 15:35
标题: 初学者。大家帮忙了,pthread_create 调用失败
谢谢




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2