1. 程式人生 > >編譯器錯誤:/tmp/ccyOgqYQ.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status

編譯器錯誤:/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 <stdio.h>
#include <stdlib.h>
#include <sys/types.h>

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;

}