linux c语言问题

/*hello_multi.c-amulti-theadedhelloworldprogram*/#include<stdio.h>#include<pthread.h>... /*hello_multi.c - a multi - theaded hello world program*/
#include <stdio.h>
#include <pthread.h>
#define NUM 5
int main(void)
{
pthread_t t1,t2;
void *print_msg(void *);
pthread_create (&t1,NULL,print_msg,(void *)"hello");
pthread_create (&t2,NULL,print_msg,(void *)"world\n");
pthread_join(t1,NULL);
pthread_join (t2,NULL);
return 0;
}

void *print_msg(void *m)
{
char *cp=(char *)m;
int i;
for(i=0;i<NUM;i++){
printf("%s",m);
fflush(stdout);
sleep(1);
}
return NULL;
}

有这些错误
main.c: 在函数‘print_msg’中:
main.c:21:9: 警告: 格式 ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘void *’ [-Wformat]
/tmp/ccHzcazW.o:在函数‘main’中:
main.c:(.text+0x29):对‘pthread_create’未定义的引用
main.c:(.text+0x4d):对‘pthread_create’未定义的引用
main.c:(.text+0x61):对‘pthread_join’未定义的引用
main.c:(.text+0x75):对‘pthread_join’未定义的引用
collect2: 错误: ld 返回 1

为什么
展开
 我来答
ronghuaiyang
2013-09-29 · TA获得超过149个赞
知道小有建树答主
回答量:185
采纳率:0%
帮助的人:153万
展开全部
main函数第二行
void *print_msg(void *);
这个是函数声明,应该放在main函数的上面,不要放在里面。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
hj304huan
2013-09-29 · TA获得超过196个赞
知道小有建树答主
回答量:135
采纳率:0%
帮助的人:108万
展开全部
编译的时候有没有加上-lpthread命令?
还有printf("%s",m);应该是printf("%s",cp);吧
追问
为什么要加-lpthread
追答
lpthread表示我要用到这个库,pthread_create等等线程函数这些都依赖这个库,编译的时候得告诉编译器我需要链接这个库
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
云帆00沧海
2013-09-29 · 超过15用户采纳过TA的回答
知道答主
回答量:42
采纳率:0%
帮助的人:30.3万
展开全部
编译时加上-lpthread
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式