Unable to include cmath using GCC 5.5 on Solaris 10

san*_*ank 5 c++ gcc solaris solaris-10

I am trying to run the following test program on my Solaris 10 sparc machine using gcc 5.5.0

#include <iostream>
#include <cmath>

int main()
{
    std::cout << "exp2(4) = " << std::exp2(4) << '\n'
              << "exp2(0.5) = " << std::exp2(0.5) << '\n'
              << "exp2(-4) = " << std::exp2(-4) << '\n';
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Here are the OS details,

~$ uname -a
SunOS sovms577 5.10 Generic_147147-26 sun4v sparc SUNW,SPARC-Enterprise-T5220
~$ cat /etc/release 
                   Oracle Solaris 10 1/13 s10s_u11wos_24a SPARC
  Copyright (c) 1983, 2013, Oracle and/or its affiliates. All rights reserved.
                            Assembled 17 January 2013
Run Code Online (Sandbox Code Playgroud)

On compiling using the following command,

g++ -std=c++11 -Wall test.cpp
Run Code Online (Sandbox Code Playgroud)

I get the following error,

#include <iostream>
#include <cmath>

int main()
{
    std::cout << "exp2(4) = " << std::exp2(4) << '\n'
              << "exp2(0.5) = " << std::exp2(0.5) << '\n'
              << "exp2(-4) = " << std::exp2(-4) << '\n';
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

I installed GCC 5.5 following the instructions given here.

cod*_*eDr 0

我发现同样的错误。在标头/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/math.h中 ,我替换了以下行:

#if __cplusplus >= 201103L
using std::float_t;
Run Code Online (Sandbox Code Playgroud)

#if 0 && __cplusplus >= 201103L
using std::float_t;
Run Code Online (Sandbox Code Playgroud)

2019 年 4 月 24 日更新——@Andrew Henle 希望你知道

If you are attempting to compile C++11 on an unpatched, unupdated 
installation of Solaris 10, and are presenting this as a "fix", 
you do not understand what you are doing. 
Run Code Online (Sandbox Code Playgroud)

@Andrew Henle 说有一个“solaris”补丁可以修复 csw/include/c++/.../cmath 和 csw/lib/gcc/..../math.h,但是该补丁如何影响 csw 的安装标头未知且未指定。

2019 年 4 月 26 日更新

我使用以下软件包使用 csw gcc 安装构建了新的 binutils 和 gcc-5.5.0:

binutils-2.27.tar.bz2
cloog-0.18.1.tar.gz
gcc-5.5.0.tar.gz
gmp-5.1.2.tar.xz
mpc-1.0.1.tar.gz
mpfr-3.1.2.tar.xz
Run Code Online (Sandbox Code Playgroud)

首先构建 binutils。

../configure --prefix=$TARGET_PATH/sx64
make
make install
Run Code Online (Sandbox Code Playgroud)

我对 gcc 使用了以下配置:

../configure --prefix=$TARGET_PATH/sx64 --enable-languages=c,c++ --enable-threads=posix --enable-version-specific-runtime-libs --disable-libsanitizer --with-as=$TARGET_PATH/sx64/bin/as --with-ld=$TARGET_PATH/sx64/bin/ld --with-gnu-ld --with-gnu-as
make bootstrap
make install
Run Code Online (Sandbox Code Playgroud)

您必须使用 --with-as 和 --with-ld 来让 gcc 使用构建的 binutils 版本而不是损坏的系统版本。

使用这个编译器,我在编译有效的 c++-11 代码时没有遇到任何问题。

  • 问题中的编译器是GCC 5.5.0,它确实支持C++11。问题是底层操作系统提供的数学头似乎不支持 C++11,可能是因为相关的 Solaris 10 版本早于 C++11 的存在,而且还没有修补。请注意,当我四个月前提到 Solaris 10 补丁 119966-02 时,有关此问题的所有活动都停止了。 (2认同)