Unable to include cmath using GCC 5.5 on Solaris 10

风流意气都作罢 提交于 2019-12-23 14:57:08

问题


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

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

On compiling using the following command,

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

I get the following error,

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;

I installed GCC 5.5 following the instructions given here.


回答1:


I found the same error. In the header /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/math.h I replaced the line:

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

with

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

Update 24 Apr 2019 -- @Andrew Henle wants you to know

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 says there's a 'solaris' patch that fixes the csw/include/c++/.../cmath and csw/lib/gcc/..../math.h, but how that patch affects the installation of the csw headers is unknown and unspecified.

Update 26 Apr 2019

I built a new binutils and gcc-5.5.0 using the csw gcc installation using the following packages:

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

Build binutils first.

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

I used the following config for 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

You have to use --with-as and --with-ld to get gcc to use the binutils version built instead of the broken system versions.

Using this compiler I had no issues compiling valid c++-11 code.



来源:https://stackoverflow.com/questions/53594474/unable-to-include-cmath-using-gcc-5-5-on-solaris-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!