编译器错误:/tmp/ccyOgqYQ.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status

今天下午在编写一个c程序文件文件名:test.cpp, 文件内容见附录。使用gcc编译的时候出现/tmp/ccyOgqYQ.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status的错误。采用c++编译问题消失。在这次这个错误是由于文件名后缀引起的。我把test.cpp改为test.c后,然后再次使用gcc编译,通过。具体的原因,有待进一步的研究。

附录:test.cpp

#include
#include
#include

 

u_int64_t gen64(char type, char data, int cid, int mid)
{
    u_int64_t ret=0;
    unsigned char tmp=0;

    switch(type)
    {
        case 'P':
            tmp = 0;
            break;
        case 'C':
            tmp = 0x10;
            break;
        case 'N':
            tmp = 0x20;
            break;
        case 'A':
            tmp = 0x30;
            break;
        default:
           fprintf(stderr, "gen64 type has problem./n");
    }
    switch(data)
    {
        case 'm':
        tmp |= 0x00;
        break;
        case 's':
        tmp |= 0x01;
        break;
        case 'a':
        tmp |= 0x02;
        break;
        case 'p':
        tmp |= 0x03;
        break;
        default:
        fprintf(stderr, "gen64 data has problem./n");
    }
    ret |= ((u_int64_t)tmp << 56) + ((u_int64_t)(cid &&0xFFFF) << 32) + (u_int64_t)(mid & 0xFFFFFFFF);

    return ret;
}

int main()
{
    printf("p,m,1,1: %lu/n", gen64('P', 'm', 1, 1));

    return 0;

}

你可能感兴趣的:(编译器错误:/tmp/ccyOgqYQ.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status)