2014-11-03 275 views
0

在CentOS版本4.3上編譯以下c代碼時發生錯誤。編譯錯誤的未定義對`htole32'的引用

#include <endian.h> 
#include <stdint.h> 
#include <stdio.h> 
#include <stdlib.h> 
int main(int argc, char *argv[]) 
{ 
    union { 
     uint32_t u32; 
     uint8_t arr[4]; 
    } x; 

    x.arr[0] = 0x11; 
    x.arr[1] = 0x22; 
    x.arr[2] = 0x33; 
    x.arr[3] = 0x44; 

    printf("x.u32 = 0x%x\n", x.u32); 
    printf("htole32(x.u32) = 0x%x\n", htole32(x.u32)); 
    printf("htobe32(x.u32) = 0x%x\n", htobe32(x.u32)); 

    exit(EXIT_SUCCESS); 
} 

詳情:

$ GCC AC /tmp/ccki8bVg.o(.text+0x3a):在功能main': : undefined reference to htole32' /tmp/ccki8bVg.o(.text+0x58 ):在 功能main': : undefined reference to htobe32' collect2:LD 返回1退出狀態

似乎沒有htole32和htobe32我的服務器上。在#include <endian.h>

#define _BSD_SOURCE 

$男人htole32 無需人工錄入的htole32

+0

檢查IDE中的包含和庫標誌(或您的命令行編譯器標誌)。這只是意味着編譯無法找到您的函數引用的includes/sources /庫。可能是您的服務器中的位置無效/路徑名中有錯字。至少,將1)Command Line Build語句與標誌或2)代碼片段中的includes,sources和libraries的IDE配置。 – ha9u63ar 2014-11-03 11:24:41

回答

1

The manual page實際上有。它只在頂部有這個,不在下面的例子程序中。當然,由於你的目標系統甚至沒有手冊頁,這可能意味着它有一個不實現這個(非標準)部分的運行時環境。

+0

明白了!這些函數在版本2.9中添加到glibc中,而我的版本是2.3。 – qiaoba 2014-11-03 11:53:30