| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1256 人关注过本帖
标题:[求助]Linux下的一个线程函数(pthread_create)问题
只看楼主 加入收藏
以泪洗面
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2005-9-22
收藏
 问题点数:0 回复次数:1 
[求助]Linux下的一个线程函数(pthread_create)问题
写了个简单的创建线程的程序
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
void test1(int *num);
void test2(int *num);
void cleanup(int num1,int num2);
int g1 = 0;
int g2 = 0;
int main(int args,char *arg[])
{
pthread_t thrd1,thrd2;
int ret;

ret = pthread_create(&thrd1,NULL,(void *)test1,(void *)&g1);
if(ret)
{
perror("error 1");
exit(EXIT_FAILURE);
}
ret = pthread_create(&thrd2,NULL,(void *)test2,(void *)&g2);
if(ret)
{
perror("error 2");
exit(EXIT_FAILURE);
}
pthread_join(thrd1,NULL);
pthread_join(thrd2,NULL);
cleanup(g1,g2);
exit(EXIT_SUCCESS);
}
void test1(int *num)
{
while(*num<10)
{
printf("thrd1 counter : %d\n",*num);
(*num)++;
}
}
void test2(int *num)
{
while(*num<10)
{
printf("thrd2 counter : %d\n",*num);
(*num)++;
}
}
void cleanup(int num1,int num2)
{
printf("the result is :%d\n",num1+num2);
}

编译是出现的错误

[root@localhost thread]# gcc threadcreat.c -o threadcreat
/tmp/ccqKpQ9O.o: In function `main':
threadcreat.c:(.text+0x31): undefined reference to `pthread_create'
threadcreat.c:(.text+0x76): undefined reference to `pthread_create'
threadcreat.c:(.text+0xaa): undefined reference to `pthread_join'
threadcreat.c:(.text+0xbd): undefined reference to `pthread_join'
collect2: ld 返回 1
这是什么意思?

我去/tmp 下看了没有ccqKpQ9O.o 文件
是不是因为这个原因啊!!
搜索更多相关主题的帖子: Linux int pthread void create 
2007-11-07 10:48
boot2046
Rank: 2
等 级:新手上路
威 望:3
帖 子:168
专家分:0
注 册:2007-7-23
收藏
得分:0 
编译的时候
gcc threadcreat.c -o threadcreat -lpthread

Linux是简单的,你不需要成为天才也能理解这种简单,Windows是复杂的,就算你是天才也不能理解这种复杂
2007-11-07 17:27
快速回复:[求助]Linux下的一个线程函数(pthread_create)问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013838 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved