LinuxSir.cn,穿越时空的Linuxsir!

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

线程程序编译错误

[复制链接]
发表于 2007-4-26 23:20:05 | 显示全部楼层 |阅读模式
正在学习线程程序编写,老是编译错误,帮我看看,谢谢!
程序:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
void * mythread(void * arg);
int main()
{
        pthread_t th;
        int kk;
        kk=pthread_create(&th,NULL,mythread,NULL);
        if (kk!=0)
                exit(0);
        for(;;)
        {
                printf("Main process\n");
                sleep(3);
        }
}
void * mythread(void * arg)
{
        for(;;)
        {
                printf("Thread\n");
                sleep(1);
        }
        return NULL;
}
错误信息:
[youngtrips@localhost ~]$ g++ -o pthreadtest test.cpp
/tmp/cclQnx0K.o: In function `main':
test.cpp.text+0x3e): undefined reference to `pthread_create'
collect2: ld 返回 1
[youngtrips@localhost ~]$
发表于 2007-4-27 01:38:32 | 显示全部楼层
没有链接线程库,用如下命令编译/链接:
gcc foo.c -lpthread
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-27 08:18:36 | 显示全部楼层
Post by MMMIX
没有链接线程库,用如下命令编译/链接:
gcc foo.c -lpthread
谢谢,我试了,编译 c程序就可以,但是编译C++就出现错误:
/tmp/cc2PQGzn.o.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld 返回 1
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-4-27 08:21:42 | 显示全部楼层
Post by youngtrips
谢谢,我试了,编译 c程序就可以,但是编译C++就出现错误:
/tmp/cc2PQGzn.o.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld 返回 1
可以编译了,不好意思,我弄错了命令,谢谢!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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