dominique120
dominique120

Reputation: 1302

Clang: 'cmath' file not found

I'm compiling my project with clang but I'm having an odd error:

[ 1%] Building CXX object CMakeFiles/tfs.dir/src/actions.cpp.o
In file included from /home/travis/build/dominique120/miniature-adventure/src/actions.cpp:20:
In file included from /home/travis/build/dominique120/miniature-adventure/src/otpch.h:27:
/home/travis/build/dominique120/miniature-adventure/src/definitions.h:39:10: fatal error:
'cmath' file not found
 #include <cmath>
 ^
make: *** [all] Error 2

My actions.cpp line 20:

#include "otpch.h"

otpch.h line 27:

#include "definitions.h"

definitions.h line 31:

#include <cmath>

I made a few edits but I have no idea what is causing this error, edits here: https://github.com/dominique120/miniature-adventure/commits/master

PS: GCC just dumps a ton of errors: https://travis-ci.org/dominique120/miniature-adventure/jobs/21905513

Upvotes: 6

Views: 18497

Answers (4)

moxi
moxi

Reputation: 1

search from APP STORE, install xcode can resolve it

Upvotes: 0

Adversus
Adversus

Reputation: 2226

Had the same problem with clang 14 on ubuntu 23.04. In my case it was fixed by removing libgcc-13-dev. Before removing:

clang++-14 -v          
Ubuntu clang version 14.0.6
<snip>
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13

After:

clang++-14 -v
Ubuntu clang version 14.0.6
<snip>
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12

Upvotes: 0

Bram
Bram

Reputation: 8263

I had the same issue on Ubuntu 22.04 with libstdc++-11-dev installed.

After doing:

sudo apt install libstdc++-12-dev

...the error went away.

It seems to occur with libstdc++-11 only?

Upvotes: 10

Calaf
Calaf

Reputation: 10817

After googling for a problem I was having on macOS, I came to your post. I am sharing a solution, even though it applies only to Mac users.

Chances are you upgraded Xcode (or it was upgraded for you) and you continue to use an old compilation scheme.

Determine which of the following directories actually exists on your disk:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/

and make sure that among your compilation switches you have -I along with a directory that exists.

Upvotes: 4

Related Questions