16.04 clang:gcc 工具链选择错误

16.04 clang:gcc 工具链选择错误

我有两个 16.04 系统,分别装有 gcc(5.4.0 和 6.0.0)和 clang 3.8(1:3.8-33ubuntu3.1)。在第一个系统上,clang 成功编译了 C++ 代码;添加 -v 后,基本输出部分如下:

Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/5.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/6.0.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.0.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6.0.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0
[...]
#include <...> search starts here:
 /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0
 /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/x86_64-linux-gnu/c++/5.4.0
 /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/backward
 /usr/local/include
 /usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.

但是,在另一个系统上,它失败了;详细输出显示

Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/5.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/6.0.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.0.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6.0.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.0.0

但是此版本的GCC6不包含头文件,因此编译失败:

#include <...> search starts here:
 /usr/bin/../lib/gcc/x86_64-linux-gnu/6.0.0/../../../../include/c++
 /usr/local/include
 /usr/lib/llvm-3.8/bin/../lib/clang/3.8.0/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
In file included from TimeHelper.cc:1:
./TimeHelper.hh:4:10: fatal error: 'cstdint' file not found
#include <cstdint>

标题存在,/usr/include/c++/5/但是此路径未列出。(已安装 libstdc++-5-dev。)

系统并不完全相同,但都是全新的(今天更新)。

如何找出问题根源?

首选工具链是硬连线的还是在配置文件中建议的?

NB 尝试明确指定--gcc-toolchain一个值,例如/usr/lib/gcc/x86-64-linux-gnu/5失败:似乎 clang 无法将该目录识别为 GCC 安装路径。与此不同,指定手动 GCC 构建的目标目录成功(但我希望看到它默认工作)。

答案1

安装 clang 4.0(这本身并不能解决问题)、删除 clang 3.8 的其余部分、gccgo 并从相同的软件包中重新安装 GCC 5 后,此问题已修复。现在它会选择正确的版本。

由于缺乏选择算法细节,我无法确切地说出它们中哪些导致了这个结果。无论如何,它有效。

答案2

在工作的机器上:

$ find /usr/include/c++/ -name cstdint
/usr/include/c++/5/tr1/cstdint
/usr/include/c++/5/cstdint
$ dpkg -S /usr/include/c++/5/cstdint
libstdc++-5-dev:amd64: /usr/include/c++/5/cstdint

所以它在libstdc++-5-dev

http://packages.ubuntu.com/xenial/libstdc++-5-dev

http://packages.ubuntu.com/xenial/amd64/libstdc++-5-dev/filelist

让我们来看看libstdc++-6-dev

http://packages.ubuntu.com/zesty/libstdc++-6-dev

http://packages.ubuntu.com/zesty/arm64/libstdc++-6-dev/filelist

...
/usr/include/c++/6/cstdint
...
...
/usr/include/c++/6/tr1/cstdint
...

相关内容