无法在Solaris 10上使用GCC 5.5包含cmath

问题描述 投票:4回答:1

我正在尝试使用gcc 5.5.0在我的Solaris 10 sparc机器上运行以下测试程序

#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;
}

以下是操作系统详细信息,

~$ 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

在使用以下命令进行编译时,

g++ -std=c++11 -Wall test.cpp

我收到以下错误,

In file included from /opt/csw/include/c++/5.5.0/cmath:44:0,
                 from test.cpp:2:
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/math.h:52:12: error: ‘std::float_t’ has not been declared
 using std::float_t;
            ^
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/math.h:53:12: error: ‘std::double_t’ has not been declared
 using std::double_t;
            ^
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/math.h:55:12: error: ‘std::fpclassify’ has not been declared
 using std::fpclassify;
            ^
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/math.h:56:12: error: ‘std::isfinite’ has not been declared
 using std::isfinite;

我按照here的说明安装了GCC 5.5。

c++ gcc solaris solaris-10
1个回答
0
投票

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

#if __cplusplus >= 201103L
using std::float_t;

#if 0 && __cplusplus >= 201103L
using std::float_t;

更新于2002年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. 

@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

首先构建binutils。

../configure --prefix=$TARGET_PATH/sx64
make
make install

我使用以下配置为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

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

使用这个编译器,编译有效的c ++ - 11代码没有问题。

© www.soinside.com 2019 - 2024. All rights reserved.