这看起来很奇怪。以一个简单的 C++ 程序为例
#include <cmath>
#include <iostream>
int main(void) {
std::cout << "Square root of 9 is " << sqrt(9) << std::endl;
}
使用 (4.8) 可以顺利通过,但使用(3.3) 则 g++
无法编译。clang++
edd@don:/tmp$ g++ -o cmath cmath.cpp
edd@don:/tmp$ ./cmath
Square root of 9 is 3
edd@don:/tmp$ clang++ -o cmath cmath.cpp
In file included from cmath.cpp:2:
/usr/lib/gcc/i686-linux-gnu/4.8/../../../../include/c++/4.8/cmath:41:10: \
fatal error:
'bits/c++config.h' file not found
#include <bits/c++config.h>
^
1 error generated.
edd@don:/tmp$
我怀疑我忽略了一些显而易见的事情。
我确实有相关的-dev
包:
edd@don:/tmp$ COLUMNS=72 dpkg -l | grep "clang\|llvm"
ii clang-3.3 1:3.3-5ubunt i386 C, C++ and Objective-C compiler (
ii libclang-commo 1:3.3-5ubunt i386 clang library - Common developmen
ii libclang-commo 1:3.2repack- i386 clang library - Common developmen
ii libclang1 1:3.2repack- i386 clang library
ii libclang1-3.3 1:3.3-5ubunt i386 clang library
ii libllvm3.1:i38 3.1-2ubuntu2 i386 Low-Level Virtual Machine (LLVM),
ii libllvm3.2:i38 1:3.2repack- i386 Low-Level Virtual Machine (LLVM),
ii libllvm3.3:i38 1:3.3-5ubunt i386 Low-Level Virtual Machine (LLVM),
ii llvm-3.3 1:3.3-5ubunt i386 Low-Level Virtual Machine (LLVM)
ii llvm-3.3-dev 1:3.3-5ubunt i386 Low-Level Virtual Machine (LLVM),
ii llvm-3.3-runti 1:3.3-5ubunt i386 Low-Level Virtual Machine (LLVM),
edd@don:/tmp$
编辑:我没有检查 Bug 跟踪系统,这是事实上在 Launchpad 上。
编辑2: 在Ubuntu 16.10中,它终于起作用了:
edd@max:~/src/progs/C++(master)$ clang++ -o cmath cmath.cpp
edd@max:~/src/progs/C++(master)$ ./cmath
Square root of 9 is 3
edd@max:~/src/progs/C++(master)$
使用clang++
版本3.8.1。
答案1
它(最终)在 Ubuntu 16.10 中运行:
edd@max:~/src/progs/C++(master)$ cat cmath.cpp
#include <cmath>
#include <iostream>
int main(void) {
std::cout << "Square root of 9 is " << sqrt(9) << std::endl;
}
edd@max:~/src/progs/C++(master)$ clang++ -o cmath cmath.cpp
edd@max:~/src/progs/C++(master)$ ./cmath
Square root of 9 is 3
edd@max:~/src/progs/C++(master)$