LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 728|回复: 2

pthread,错误,各位大虾帮帮忙

[复制链接]
发表于 2005-1-3 11:22:21 | 显示全部楼层 |阅读模式
下面是源码和错误提示

[root 09:20:58 develop:]#vi pthread.c
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

void task1(int *counter);
void task2(int *counter);
void cleanup(int counter1,int counter2);

int g1=0;
int g2=0;

int main(int argc, char*argv[]){
        pthread_t thrd1,thrd2;
        int ret;

        /* creat the first thread*/
        ret=pthread_creat(&thrd1,NULL,(void *)task1,(void*)&g1);
        if(ret){
        perror("pthread_creat:task1");
        exit(EXIT_FAILURE);
        }

pthread.c                                                     1,1           顶端
"pthread.c" 57L, 972C
[root 09:20:48 develop:]# gcc pthread.c
/tmp/cc84hOAm.o: In function `main':
/tmp/cc84hOAm.o(.text+0x17): undefined reference to `pthread_creat'
/tmp/cc84hOAm.o(.text+0x57): undefined reference to `pthread_creat'
/tmp/cc84hOAm.o(.text+0x90): undefined reference to `pthread_join'
/tmp/cc84hOAm.o(.text+0xa1): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
发表于 2005-1-3 12:10:45 | 显示全部楼层
1. 是pthread_create吧?
2. gcc pthread.c -lpthread
发表于 2005-1-3 21:22:50 | 显示全部楼层
貌似应该 让pthread启动的函数的类型 变成 void*
反正除了void类型,其他的因该都可以吧
还有  pthread_create 不是pthread_creat
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表