【问题标题】:AARCH64 gcc #include <stdint.h> failsAARCH64 gcc #include <stdint.h> 失败
【发布时间】:2018-01-19 04:38:31
【问题描述】:

我正在尝试使用我需要 stdint.h 的源文件之一中的 aarch64 交叉编译器从 x86 计算机为树莓派 3 编译一些内核代码,但是当我尝试编译时它失败了

>make
rm kernel8.elf *.o >/dev/null 2>/dev/null || true
rm -rf *.o *.img *.elf
aarch64-linux-gnu-gcc -Wall -c start.s -o start.o
aarch64-linux-gnu-gcc -Wall -c delays.c -o delays.o
In file included from gpio.h:4:0,
                 from delays.c:26:
/usr/lib/gcc/aarch64-linux-gnu/7/include/stdint.h:9:16: fatal error: stdint.h:     No such file or directory
 # include_next <stdint.h>
                ^~~~~~~~~~
compilation terminated.
make: *** [Makefile:15: delays.o] Error 1

我正在运行 Fedors 26 并且已经使用过

sudo dnf install *aarch64*

所以我有所有合适的包或应该有。

【问题讨论】:

  • 你需要检查几件事:1)uname -a(确保内核是arm8)2)你是否安装了构建工具(运行以下命令:sudo apt-get install -y bc build-essential gcc-aarch64-linux-gnu)。
  • 使用-std=c11 -pedantic-errors 编译以确保您在C 编译器模式下使用gcc。
  • @MilindDeore 我的问题不清楚我现在已经澄清我正在使用 aarch64 编译器作为基于 x86 计算机的交叉编译器。
  • @Lundin 我已经编辑了我的 makefile 以包含您建议的内容,这没有任何区别。
  • @OliverStrong 安装包glibc-headers 修复了吗?

标签: c gcc embedded arm64 stdint


【解决方案1】:

我建议为 x86 使用最新的 Linaro toolchain:过去我在使用主流 Debian/Ubuntu 提供的 ARM 交叉编译器时遇到过几个问题。

使用以下 stdint.c 示例:

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
    printf("The size of an uint32_t is %d.\n", sizeof(uint32_t));
    return EXIT_SUCCESS;
}


mkdir -p /opt/linaro
wget https://releases.linaro.org/components/toolchain/binaries/latest/aarch64-linux-gnu/gcc-linaro-7.2.1-2017.11-i686_aarch64-linux-gnu.tar.xz
tar Jxvf gcc-linaro-7.2.1-2017.11-i686_aarch64-linux-gnu.tar.xz -C /opt/linaro
/opt/linaro/gcc-linaro-7.2.1-2017.11-i686_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc -o stdint stdint.c


编译应该会成功,你应该会得到一个工作的 AARCH64 可执行文件:

readelf -h stdint
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           AArch64
  Version:                           0x1
  Entry point address:               0x4003f0
  Start of program headers:          64 (bytes into file)
  Start of section headers:          4872008 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         6
  Size of section headers:           64 (bytes)
  Number of section headers:         37
  Section header string table index: 36


如果你有一台 x86_64 开发 PC,当然最好使用 Linaro 工具链的 x86_64 version

【讨论】:

    猜你喜欢
    • 2023-03-04
    • 1970-01-01
    • 2021-10-07
    • 2022-08-15
    • 2018-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-04
    相关资源
    最近更新 更多