中国Linux公社论坛's Archiver

efengyu 发表于 2006-4-29 16:55

创建线程求救

小弟写了个程序想验证一下,但总是有这种错误
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>

void task(int *counter)
{
  fprintf(stderr,"task runing\n");
}

int arg;
static pthread_t tid;

int main()
{
  int ret=pthread_create(&tid,NULL,task,(void*)&arg);
  if(ret)
  {
    fprintf(stderr,"success\n");
  }
}  


[root@localhost testdir]# gcc main.c -o main
main.c: In function `main':
main.c:15: warning: passing arg 3 of `pthread_create' from incompatible pointer
type
/tmp/cc67xs1l.o(.text+0x40): In function `main':
: undefined reference to `pthread_create'
collect2: ld returned 1 exit status

那位兄弟能给我解释一下,多谢了

moonhalf 发表于 2006-4-30 09:19

[code:1]
gcc -o main main.c -lpthread
[/code:1]

genius-wh 发表于 2010-8-15 13:41

子程序类型应该是void * 即void * task(int *counter)

JCheung 发表于 2010-8-30 12:12

恩 ,楼上说的对
改成void *task(int *conunter)

好好看下函数原形就可以解决的问题。

页: [1]

Powered by Discuz! Archiver 6.1.0F  © 2001-2007 Comsenz Inc.