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