【问题标题】:Building cross compiler: pthread.h: No such file or directory构建交叉编译器:pthread.h:没有这样的文件或目录
【发布时间】:2019-05-20 17:21:02
【问题描述】:

我目前正在尝试为aarch64-linux-gnu 目标编译我自己的 gcc 9.1.0 交叉编译器。我用过这个教程:https://wiki.osdev.org/GCC_Cross-Compiler

gcc 和 g++ 编译器的编译进度似乎没有错误地完成,但是当我尝试使用命令 libgcc 编译 make all-target-libgcc 时总是遇到此错误:

In file included from ../../../gcc-9.1.0/libgcc/gthr.h:148,
                 from ../../../gcc-9.1.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:10: fatal error: pthread.h: No such file or directory
   35 | #include <pthread.h>
      |          ^~~~~~~~~~~
compilation terminated.

g++ --version 在我的构建机器上打印:

g++ (GCC) 9.1.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我对@9​​87654328@ 的配置命令是: ../gcc-9.1.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --without-headers 与:

export TARGET=aarch64-linux-gnu
export PREFIX=/opt/aarch64-linux-gnu

我忘记了什么?

【问题讨论】:

  • pthread.h 是一个 glibc 头文件,由包 glibc-devel / libc6-dev ...提供。包名取决于你使用的操作系统。
  • 为什么没有找到 pthread? pthread.h 是否应该在 gcc 构建树中?我的意思是我可以通过find 找到它。
  • 编译器应该使用构建的pthread.h还是主机的pthread.h

标签: linux gcc makefile g++


【解决方案1】:

来自 GCC 安装手册:

为了构建 GCC,C 标准库和头文件必须是 存在于目标库的所有目标变体 已构建(不仅是宿主 C++ 编译器的变体)。

所以你需要一个用于 aarch64 的 libc。

如果你想自己构建它,Preshing 有一个很好的 article 关于这个主题,我还没有完整阅读,但无论如何推荐。他甚至有一张提到pthread.hlibgcc.a的照片。

AFAIK,GCC 可以获取到newlib 源的符号链接,并在使用目标库构建完整的交叉编译器的过程中自动构建它。不确定 Glibc。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-05
    • 2019-04-22
    • 2021-10-17
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    相关资源
    最近更新 更多