OS X 10.8.5 上的 C++ math.h

C++ math.h on OS X 10.8.5

我有一个 C++ 程序无法在 OS X 10.8.5 下使用 g++ 编译器编译。问题似乎与 math.h 头文件有关。

这是g++的版本是

g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/Users/densmore3/local/usr/local/bin/../libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/lto-wrapper
 Target: x86_64-apple-darwin14.0.0
 Configured with: ../gcc-4.9-20141029/configure --enable-   languages=c++,fortran
 Thread model: posix
 gcc version 4.9.2 20141029 (prerelease) (GCC) 

有 40-50 个以下类型的错误。代码在 10.6 上编译得很好。怎么回事?

/Users/xxxx/local/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include-fixed/math.h:203:1: error: ‘__header_always_inline’ does not name a type
__header_always_inline int __inline_isfinitef(float);

Users/densmore3/local/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include-fixed/math.h:580:27: error: expected initializer before ‘__AVAILABILITY_INTERNAL__MAC_10_0_DEP__MAC_10_9’
extern float __inff(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);

这是一段测试代码,它给出了与我的真实代码相同的错误。如果我删除 math.h include 语句,错误就会消失。

#include <iostream>
#include <math.h>
#include <stdio.h>
//#include <complex>
//#include <vector>

int main(int argc, const char * argv[])
{

    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}

我使用的编译命令是:

g++ test.cpp

gcc-4.8 是在 OS X 10.8 上使用的正确版本。