这是我第一次使用clang
。我注意到,clang 引用 std 库的任何错误都如下所示:
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/ostream:245:7:
^^^ ^^^ ^^^
所以它看起来像 clang 链接——或者至少包括——gcc 库。
我使用的命令:clang++ -c -Wall -Wextra -Werror -g test.cpp -o test.o
。 (该程序有一个故意的错误只是为了证明这一点)。
这怎么可能?我能做些什么来使clang
使用它自己的库(但不破坏 gcc)?
附加信息:
我使用的是 Ubuntu 14.04 机器。
clang++ --version
Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
Target: x86_64-pc-linux-gnu
Thread model: posix
g++ --version
g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
我之前安装过几个版本(同时将它们与update-alternatives
) of gcc
with apt-get
。现在我只有4.8
(我已经卸载了其他的)。那我会不会搞砸了什么?我从未安装过 clang (我猜它是 Ubuntu 的默认设置)。
只是为了澄清:正确的程序编译并运行在clang++
.
进一步测试:我知道gcc
还没有实现类似的类型is_trivially_constructible
并将操作移至iostream
在他们的标准 c++11 库中(https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html)并且 clang 具有完整的 c++11 符合库,因此我测试了使用 clang 编译的库,并得到了相应的 gcc 错误,这仅确认 clang 正在使用 gcc 库。
一个非常基本的程序
#include <iostream>
using namespace std;
int main() {
cout << "Yada Yada" << endl;
return 0;
}
在 clang++ 中使用 -std=c++1y 编译时出现此错误:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/iostream:39:
...
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/cstdio:120:11: error: no member named 'gets' in the global namespace
using ::gets;
~~^
所以现在我无法编译任何东西c++1y
铿锵地。