-4

When I try to build a C project in code:blocks on ubuntu 14.04 that uses GLM I get this

fatal error: cmath: No such file or directory

Any ideas how to fix this?

amanuel2
  • 4,508
  • 4
  • 36
  • 67

1 Answers1

6

The problem here is that you are building a C project in Code::Blocks. It gives you the error:

fatal error: cmath: No such file or directory

because you are supposed to be building a C++ project, but the header <cmath> is only available for C++, not C. Look here for more references

HongboZhu
  • 4,442
  • 3
  • 27
  • 33
amanuel2
  • 4,508
  • 4
  • 36
  • 67
  • That is true. However, when I go to settings > compiler > toolchain executables, it shows GCC for C and G++ for C++ – firstname gklsodascb Oct 15 '16 at 19:30
  • @firstnamegklsodascb yes so use `G++` For `C++` .. `G++` Is a Compiler for `C++` while `GCC` Is a compiler for `C` – amanuel2 Oct 15 '16 at 19:32
  • Also the part that includes cmath is part of an entirely different c++ library (GLM) – firstname gklsodascb Oct 15 '16 at 19:33
  • I was under the impression that it would automatically compile C with GCC and C++ with g++. Also I though c++ was backwards compatible – firstname gklsodascb Oct 15 '16 at 19:34
  • @firstnamegklsodascb backward compatible? If you mean "I thought C++ Can compile C Programs" , Absolutely not! There are cases for which there is valid C Code and Invalid C++ Code. – amanuel2 Oct 15 '16 at 19:35
  • @firstnamegklsodascb GCC will only compile a file in C++ if the extension is `.cc` or `.cpp`, or you specify it with `-x` or `-std`. You can also use g++ which defaults to C++ instead of C – Rakete1111 Oct 15 '16 at 19:36
  • I mean they are pretty much the same language. Isn't valid C guaranteed to work when compiled with G++? – firstname gklsodascb Oct 15 '16 at 19:48
  • @firstnamegklsodascb **No, not at all!** see [**this**](http://stackoverflow.com/questions/861517/what-issues-can-i-expect-compiling-c-code-with-a-c-compiler). – amanuel2 Oct 15 '16 at 19:48
  • @firstnamegklsodascb: This has been discussed a hundred times here and elsewhere already. Do research on your own and feel free where C allows something like `const int i = 10; static int a[i];` or C++ `auto int i = 10, a[i];`. **for example**. And gcc is not the actual compiler, but front end only. It also calls the assembler, linker, etc. depending on the arguments.. – too honest for this site Oct 15 '16 at 20:01