编译GCC遇到的“pthread.h” not found问题

在LFS的第五章从源码编译freestanding的GCC时遇到如下报错

./gthr-default.h:35:10: fatal error: pthread.h: No such file or directory
   35 | #include <pthread.h>

书上给的参考配置指令为

../configure                  \
    --target=$LFS_TGT         \
    --prefix=$LFS/tools       \
    --with-glibc-version=2.35 \
    --with-sysroot=$LFS       \
    --with-newlib             \
    --without-headers         \
    --enable-initfini-array   \
    --disable-nls             \
    --disable-shared          \
    --disable-multilib        \
    --disable-decimal-float   \
    --disable-threads         \
    --disable-libatomic       \
    --disable-libgomp         \
    --disable-libquadmath     \
    --disable-libssp          \
    --disable-libvtv          \
    --disable-libstdcxx       \
    --enable-languages=c,c++

我首先尝试了一下删除上述的一堆disable,使用了如下的配置指令(主要是好奇configure会不会自动推断出来一些库和feature没办法支持,比如threads)

../configure                  \
    --target=$LFS_TGT         \
    --prefix=$LFS/tools       \
    --with-glibc-version=2.35 \
    --with-sysroot=$LFS       \
    --with-newlib             \
    --without-headers         \
    --enable-initfini-array   \
    --disable-nls             \
    --disable-shared          \
    --disable-multilib        \

然后果不其然,我得到了如下报错

./gthr-default.h:35:10: fatal error: pthread.h: No such file or directory
   35 | #include <pthread.h>

于是我尝试了make clean,然后使用书上的配置指令重新configure。不解的是,仍然得到了上面的pthread.h not found的报错(预期由于移除了线程支持,应该不再依赖pthread.h头文件)。

发现使用rm -rf *把build目录全部删除后再重新configure就成功了。这说明是前面的make clean没有讲配置文件删除干净。

一番搜索后,发现了GNU automake的说明以及GNU coding styles的说明。

在上面coding styles的文档中有如下说明

‘clean’
Delete all files in the current directory that are normally created by building the program. Also delete files in other directories if they are created by this makefile. However, don’t delete the files that record the configuration. Also preserve files that could be made by building, but normally aren’t because the distribution comes with them. There is no need to delete parent directories that were created with ‘mkdir -p’, since they could have existed anyway.

‘distclean’
Delete all files in the current directory (or created by this makefile) that are created by configuring or building the program. If you have unpacked the source and built the program without creating any other files, ‘make distclean’ should leave only the files that were in the distribution. However, there is no need to delete parent directories that were created with ‘mkdir -p’, since they could have existed anyway.
Delete .dvi files here if they are not part of the distribution.

在上面automake的文档中,定义了如下的clean语义

  • If make built it, and it is commonly something that one would want to rebuild (for instance, a .o file), then mostlyclean should delete it.
  • Otherwise, if make built it, then clean should delete it.
  • If configure built it, then distclean should delete it.
  • If the maintainer built it (for instance, a .info file), then maintainer-clean should delete it. However maintainer-clean should not delete anything that needs to exist in order to run ‘./configure && make’.

所以我之前的操作问题在于不应该使用make clean,而应该使用make distclean

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值