【问题标题】:GCC: Building cross-compiler for ARM - pthread.h not foundGCC:为 ARM 构建交叉编译器 - 未找到 pthread.h
【发布时间】:2014-09-30 06:08:00
【问题描述】:

使用 Ubuntu 12.04 主机,我仔细按照这里的 SO 答案 (Recipe for Compiling Binutils and GCC Together) 在一个树中构建 GCC 和 binutils 及其所有依赖项。

这是我在构建目录中执行的配置行:

    ../gcc-4.9.0/configure --target=arm-linux-gnueabi --prefix=/home/mint/cross-arm --disable-werror

Makefile 配置正确,然后我运行:

    sudo make -j8

我进入编译过程一段时间,然后最终出现错误:

    In file included from ../../../gcc-4.9.0/libgcc/gthr.h:148:0,
             from ../../../gcc-4.9.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
#include <pthread.h>
                 ^
compilation terminated.
make[2]: *** [_gcov_flush.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from ../../../gcc-4.9.0/libgcc/gthr.h:148:0,
             from ../../../gcc-4.9.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
#include <pthread.h>
                 ^
compilation terminated.
make[2]: *** [_gcov_execlp.o] Error 1
In file included from ../../../gcc-4.9.0/libgcc/gthr.h:148:0,
             from ../../../gcc-4.9.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
#include <pthread.h>
                 ^
In file included from ../../../gcc-4.9.0/libgcc/gthr.h:148:0,
             from ../../../gcc-4.9.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
#include <pthread.h>
                 ^
compilation terminated.
make[2]: compilation terminated.
*** [_gcov_fork.o] Error 1
make[2]: *** [_gcov_execl.o] Error 1
In file included from ../../../gcc-4.9.0/libgcc/gthr.h:148:0,
             from ../../../gcc-4.9.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:21: fatal error: pthread.h: No such file or directory
#include <pthread.h>
                 ^
compilation terminated.
make[2]: *** [_gcov_execle.o] Error 1
make[2]: Leaving directory `/home/mint/Workspaces/src/build/arm-linux-gnueabi/libgcc'
make[1]: *** [all-target-libgcc] Error 2
make[1]: Leaving directory `/home/mint/Workspaces/src/build'
make: *** [all] Error 2

我是否缺少某个阻止此构建的依赖项?

附:我在构建之前通过 apt-get 安装了“build-essential”。

【问题讨论】:

  • 让Buildroot 为您工作怎么样?
  • 是不是很无痛?
  • 到目前为止我没有遇到任何问题。 BR 提供了几种获取工具包的方法。只需阅读文档的this 部分并尝试最适合您需求的方式。在大多数情况下,我使用外部工具链,当我需要重新编译整个 rootfs 时,它可以节省时间。
  • 如何知道如何维护 buildroot 或在不学习的情况下替换它。就像不去上数学课,因为有计算器……

标签: gcc pthreads cross-compiling gnu


【解决方案1】:

该错误表明 C 库存在一些问题。

要构建 GCC 编译器,您需要预构建的 binutils + 预构建的 C 库。

如果是交叉编译器,一种可能的途径是:

  1. 确保您已预构建 binutils(交叉编译构建)
  2. 交叉编译 GCC: 添加配置选项 --without-headers。现在编译(请参阅下面链接中的 make 目标)
  3. 编译您的 C 库并在为目标编译程序时指向它

在GCC Cross Compiling 处查看交叉编译 gcc 的一些说明。然后“安装”适当的 C 库(glibc / newlib)。

另外,(如果您还没有这样做的话)可能值得确保 bintutils 的 --prefix 和 gcc 交叉编译构建位于同一位置。

【讨论】:

  • 如果您查看链接的 SO 答案,我已将 gcc-4.9.0/ 目录中的所有 GCC 依赖项符号链接,我运行 ./configure ,如上所示,我期望的就是一切使用这些选项构建。这不是推荐的方法吗?
  • SO 答案与交叉编译器构建没有直接关系。尽管请记住,在公共 dir 源代码树中构建 binuitls + gcc 与您是否正在构建交叉编译器是正交的。手头的问题是因为整个交叉编译设置的另一个依赖项 = 这是 C 库。
  • 我明白了。我已阅读您提供的链接。如果我按指定编译,它将返回一个裸编译器,其中一个简单的 stdio.h 导入会使它崩溃。我将如何安装 C 库后编译?
  • 是的,没错。现在对于 C 库,您可以使用 newlib/glibc。配置和编译它们应该非常简单。自从我进行交叉编译器构建以来已经有一段时间了,所以不能马上给你配置命令等。
  • 您选择不使用禁用线程进行 GCC 配置有什么原因吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-05
  • 1970-01-01
  • 2013-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-20
相关资源
最近更新 更多