9

This seems odd. Take a simple C++ program

#include <cmath>
#include <iostream>

int main(void) {

    std::cout << "Square root of 9 is " << sqrt(9) << std::endl;

}

which passes fine with g++ (4.8) but fails to compile with clang++ (3.3).

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$ 

I suspect I am missing something blatantly obvious.

And I do have the relevant -dev package:

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$ 

Edit: I had failed to check the Bug Tracking System, this is in in fact known at Launchpad.

Edit 2: In Ubuntu 16.10, it finally works:

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)$ 

using clang++ version 3.8.1.

  • I see bug report WON'T FIXED, 13.10 isn't supported anymore, and 3.3 is removed in 15.04. So I voted to close it. – user.dz Sep 21 '15 at 4:53
  • 2
    @Sneetsher: You do understand that I filed this nearly two years ago when that distribution version and package were current? – Dirk Eddelbuettel Sep 21 '15 at 11:54
  • Yeah, I do. I just see the question get aged away. I don't any one is going to answer. But if want, you can write one mention the workaround from the bug report that add -i /path-to-std-headers. That will any coming later here. 7 votes seem have some attraction. :) – user.dz Sep 21 '15 at 12:05
  • 1
    For what it is worth this still does not build (by default) in 2016 under 16.04. Sad. – Dirk Eddelbuettel Nov 4 '16 at 20:33
  • I will give it a try and let you know. – user.dz Nov 4 '16 at 21:56
2

It (at last) works in 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)$ 

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.