Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In xcode when including cmath get error: '::acos' has not been declared, etc

Tags:

c++

xcode

cmath

I get the following errors when trying to build a small and simple project that includes <cmath> in Xcode:

cmath: '*' has not been declared
'::acos' has not been declared
In file included from /Xcode4/Projects/libraryLAFMath/Classes/libraryLAFMath.cp
In file included from /Xcode4/Projects/libraryLAFMath/Classes/libraryLAFMath.h
'::acos' has not been declared in /Xcode4/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk/usr/include/c++/4.2.1/cmath
...

The error log complains about all the other math functions as well, sin, pow, etc, not just acos. I looked inside cmath source code and it references the globally defined corresponding math functions from math.h, ie ::acos etc. Since the root error complains about the non-existance of ::acos one would assume that math.h can't be found, but a) it exists, and b) I'd get a different error complaining that math.h can't be found.

The source code is as follows:

libraryLAFMath.cp:

#include "libraryLAFMath.h"

libraryLAFMath.h:

#include <cmath>
struct libraryLAFMath {
    void test() {
        double a = std::acos(0);
    }
};

Now, I have another project from an outside source that uses cmath and compiles fine. I tried comparing build settings between these two projects but they are pretty much the same. I am using LLVM GCC 4.2 compiler, but get similar result when using GCC 4.2, so it's not a compiler settings issue I believe.

I'm new to Xcode development and any help is appreciated.

like image 379
andrewz Avatar asked Oct 15 '10 05:10

andrewz


1 Answers

There is a file I have in my project named Math.h with a capital M, and it seems the compiler gets confused and tries to include Math.h instead of math.h.

like image 137
andrewz Avatar answered Sep 30 '22 16:09

andrewz