GCC:为ARM构建交叉编译器 - 找不到pthread.h文件

5
使用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

我是否缺少某些依赖项导致构建失败?

P.S. 在构建之前,我已经通过apt-get安装了“build-essential”。


让例如Buildroot为您完成这项工作怎么样? - yegorich
这很容易吗? - KrizzzyS
到目前为止,我没有遇到任何问题。BR提供了几种获取工具链的方法。只需阅读部分的文档,并尝试最适合您需求的方式。在大多数情况下,我使用外部工具链,这样当我需要重新编译整个rootfs时可以节省时间。 - yegorich
如果不去学习,怎么能知道如何维护Buildroot或替换它呢?这就像因为有计算器存在而不去上数学课一样... - old_timer
1个回答

0

错误提示存在C库的问题。

构建GCC编译器需要预先构建的binutils和预先构建的C库。

对于交叉编译器,一种可能的方法是:

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

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

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


如果您查看链接的SO答案,我已经在gcc-4.9.0/目录中建立了所有GCC依赖项的符号链接,我像上面展示的那样运行./configure,我期望的是使用这些选项构建所有内容。这不是一个推荐的方法吗? - KrizzzyS
SO的答案与交叉编译器构建没有直接关系。尽管请记住,在常见的dir源树中构建binuitls + gcc与是否正在构建交叉编译器无关。手头的问题是由于整个交叉编译设置的另一个依赖项引起的,即C库。 - Cherry Vanc
我明白了。我已经阅读了您提供的链接。如果按照指定的方式编译,它将返回一个裸编译器,其中简单的 stdio.h 导入会导致崩溃。那么我该如何在编译后安装 C 库呢? - KrizzzyS
1
我按照指示安装了binutils,但在执行“make all-target-libgcc”时,gcc仍然出现相同的pthread错误。 - KrizzzyS
4
你选择在GCC配置中不使用disable-threads是否有原因? - Cherry Vanc
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接