• 6331阅读
  • 2回复

创建线程求救 [复制链接]

上一主题 下一主题
离线efengyu
 

只看楼主 倒序阅读 楼主  发表于: 2006-04-29
小弟编了一个简单的创建线程程序想验证一下,确总有这种错误

#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


那位兄弟能给小弟解释一下。
[ 此贴被XChinux在2006-05-08 00:30重新编辑 ]
离线shiroki

只看该作者 1楼 发表于: 2006-05-18
加 -lpthread
--
shiro is White
ki is tree
http://www.cuteqt.com
论坛 http://www.cuteqt.com/bbs
博客 http://www.cuteqt.com/blog
博客镜像: http://sites.cuteqt.com/cuteqt
Linux/Qt/嵌入式讨论群 http://qun.qq.com/air/5699823
离线style
只看该作者 2楼 发表于: 2006-05-25
///////////////////file.cpp///////////////////
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>

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

int arg;
static pthread_t tid;

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

#g++ -o file file.cpp -pthread
快速回复
限100 字节
 
上一个 下一个