系统libc文件的Clang工具链失败

时间:2017-11-02 15:05:53

标签: c++ clang clang++ bazel

我为Clang编写了一个自定义(cc_)工具链。经过一番来回,我现在大部分都在工作。然而,它失败了:

undeclared inclusion(s) in rule '//foo:foo'
this rule is missing dependency declarations for the following files included by 'foo/foobar.cpp':
  '/usr/include/features.h'
  '/usr/include/stdc-predef.h'
  '/usr/include/x86_64-linux-gnu/sys/cdefs.h'
  '/usr/include/x86_64-linux-gnu/bits/wordsize.h'
  '/usr/include/x86_64-linux-gnu/gnu/stubs.h'
  '/usr/include/x86_64-linux-gnu/gnu/stubs-64.h'
  '/usr/include/stdint.h'
  '/usr/include/x86_64-linux-gnu/bits/wchar.h'
  '/usr/include/stdio.h'
  '/usr/include/x86_64-linux-gnu/bits/types.h'
  '/usr/include/x86_64-linux-gnu/bits/typesizes.h'
  '/usr/include/libio.h'
  '/usr/include/_G_config.h'
  '/usr/include/wchar.h'
  '/usr/include/x86_64-linux-gnu/bits/stdio_lim.h'
  '/usr/include/x86_64-linux-gnu/bits/sys_errlist.h'
  '/usr/include/math.h'
  '/usr/include/x86_64-linux-gnu/bits/math-vector.h'
  '/usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h'
  '/usr/include/x86_64-linux-gnu/bits/huge_val.h'
  '/usr/include/x86_64-linux-gnu/bits/huge_valf.h'
  '/usr/include/x86_64-linux-gnu/bits/huge_vall.h'
  '/usr/include/x86_64-linux-gnu/bits/inf.h'
  '/usr/include/x86_64-linux-gnu/bits/nan.h'
  '/usr/include/x86_64-linux-gnu/bits/mathdef.h'
  '/usr/include/x86_64-linux-gnu/bits/mathcalls.h'
  '/usr/include/assert.h'
  '/usr/include/string.h'
  '/usr/include/xlocale.h'

那么如何处理这些文件呢?只需对工具链进行硬编码即可?或者是否有一个开关来忽略系统的依赖关系(/usr)?或者更确切地说使用像 musl newlib bionic 这样的密封libc。

修改

有关实际工具链的更多详细信息,请参阅:https://github.com/abergmeier/bazel_toolchains

1 个答案:

答案 0 :(得分:1)

您需要将编译器的内置包含路径放入crosstool proto的cxx_builtin_include_directory字段中,因此Bazel知道在包含依赖性验证期间忽略它们。您可以通过运行类似

的内容来查看内置包含gcc兼容编译器的路径
$ $CC -x c++ -v - -c -o /dev/null < /dev/null

并寻找输出

#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/7
 /usr/include/x86_64-linux-gnu/c++/7
 /usr/include/c++/7/backward
 /usr/lib/gcc/x86_64-linux-gnu/7/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/7/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include