In xcode, when cmath is turned on, an error occurs: ':: acos' was not declared, etc.

I get the following errors when trying to create 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 also complains about all other mathematical functions, sin , pow , etc., and not just acos . I looked into the cmath source code and references the globally defined corresponding math functions from math.h , i.e. ::acos etc. Since the root error complains about the non-existence of ::acos , it can be assumed that math.h can't be found, but a) it exists, and b) I would get another error complaining that math.h could not 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 external source that uses cmath and compiles fine. I tried to compare build settings between the two projects, but they are almost the same. I use the LLVM GCC 4.2 compiler, but I get a similar result when using GCC 4.2, so I do not think this is a problem with the compiler options.

I am new to Xcode development and any help is appreciated.

+7
c ++ xcode cmath
source share
2 answers

There is a file with M in my project named Math.h , and it seems that the compiler is confused and is trying to include Math.h instead of Math.h

+12
source share

I posted this answer to an alternative thread on this topic, but thought it was also worth it here:

I had this problem - it drove me crazy, but I tracked the cause, and it was slightly different from what I saw in this problem.

In this case, the common cmath header (or math.h is the error and solution found in C ++ or C) included switches for the architectural environment to include subheadings related to architecture. The architecture switch (environment variable) was not defined, so it casted and did not actually include the headers that really defined the math functions.

So there was really one math.h or cmath.h, and it was included, but that was not enough to get the math functions. In my case, instead of defining an architectural variable, I instead found the location of the correct math headers and added them to my compilation path. Then the project works!

This seems to be a problem that occurs when porting Linux projects to OS-X. I assume that this can happen at any time when the project has been moved between platforms, so that the standard library headers are located differently.

+1
source share

All Articles