5

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.

bisarch
  • 1,388
  • 15
  • 31
  • Solaris 10 predates C++11 by quite a few years - early versions are contemporary with Windows XP. What exact version of Solaris 10? Has it been kept up-to-date with the latest patches and updates? Do you have problems if you remove `-std=c++11` entirely? Of if you replace it with something like `-std=c++98`? Or any of the GNU-specific C++ dialects? – Andrew Henle Dec 03 '18 at 14:22
  • 2
    @AndrewHenle Regardless, GCC 5.5 should ship with everything it needs in order to work, or not at all. To me this seems to be more of a configuration problem, or possibly a bug with GCC 5.5's Solaris support. That is, this would be a GCC problem, not a Solaris problem. – Lightness Races in Orbit Dec 03 '18 at 14:50
  • @LightnessRacesinOrbit It could very well be a problem with a version of Solaris that's too early to support C++11. The OpenCSW gcc5 packages do not supply a version of `iso/math_c99.h`, yet that is where `typedef float float_t` is done under the `std` namespace for C++11 on Solaris 11. Yet the Illumos source at http://src.illumos.org/source/xref/illumos-gate/usr/src/head/iso/math_c99.h#173 doesn't have any `#if __cplusplus > 201103L namespace std { #endif`, meaning C++11 support was added to Solaris *after* OpenSolaris was forked from Solaris 10. OP's Solaris 10 could predate C++11 support. – Andrew Henle Dec 03 '18 at 20:02
  • (cont) [OpenCSW requires at least Solaris 10 Update 8](https://www.opencsw.org/manual/for-administrators/faq.html), and even [that's from 2009](https://en.wikipedia.org/wiki/Solaris_(operating_system)#Version_history), meaning it could be missing C++11 support, although it's possible an Oracle patch could have addressed that. Normally, I'd agree with you that this is strictly a GCC issue, but in this case it appears that where the problem could very well depend on what version of Solaris 10 OpenCSW supports. – Andrew Henle Dec 03 '18 at 20:07
  • @AndrewHenle Added solaris version details. – bisarch Dec 04 '18 at 04:37
  • @AndrewHenle std::exp2 was added in C++11. So without the -std=c++11 flag the compilation fails with a different error message. `error: ‘exp2’ is not a member of ‘std’` – bisarch Dec 04 '18 at 04:45
  • you also have to [link the math library with `-lm`](https://stackoverflow.com/q/1033898/995714). See [Linking error - gcc -lm](https://stackoverflow.com/q/8957967/995714), [Why Am I Getting Link Errors When Calling Function in Math.h?](https://stackoverflow.com/q/103407/995714), ["undefined reference to `pow'" even with math.h and the library link -lm](https://stackoverflow.com/q/16344445/995714) – phuclv Dec 04 '18 at 05:19
  • @phuclv The problem occurs during compilation phase, not linking phase. – bisarch Dec 04 '18 at 05:26
  • @sank I know. But your compile command above doesn't have `-lm` – phuclv Dec 04 '18 at 06:24
  • @phuclv It doesn't need -lm. It is a C++ program not a C program. – bisarch Dec 04 '18 at 06:31
  • @AndrewHenle That's still a problem with the gcc5 packages rather than the OS. C++11 support is not a factor of the operating system, but of a toolchain's completion on that operating system. – Lightness Races in Orbit Dec 04 '18 at 10:45
  • @sank: You still [potentally] need `-lm` in a C++ program. – Lightness Races in Orbit Dec 04 '18 at 10:46
  • @LightnessRacesinOrbit Normally, I'd agree with you. But we don't even know if [patch 119966-02](https://updates.oracle.com/readme/119966-02) has been applied. It includes fixes for "22170821 C++11 must handle integral arguments to C99 math functions", "22212928 can fail to interact properly with glibc++ ", and "19337921 C99 math needs to be in namespace std for C++11 and later". Those three problems with GCC and C++11 appear directly related to this question. – Andrew Henle Dec 04 '18 at 11:07
  • @AndrewHenle Oh, tell you what, to be fair I did forget that distro maintainers patch common software libraries themselves as well. So you could well be right. – Lightness Races in Orbit Dec 04 '18 at 12:32

1 Answers1

0

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.

codeDr
  • 1,535
  • 17
  • 20
  • `#if 0 && __cplusplus >= 201103L` breaks C++11 support. – Andrew Henle Apr 17 '19 at 22:25
  • If the compiler supported C++11, then it probably wouldn't complain about std::float_t etc. I think there's something wrong with the inclusion of the this ''fixed'' math.h because the compiler doesn't accept it. – codeDr Apr 18 '19 at 17:35
  • 2
    The compiler in the question is GCC 5.5.0, which does support C++11. The problem is the underlying OS-supplied math headers do not appear to support C++11, likely because the version of Solaris 10 in question predates the existence of C++11 and also hasn't been patched. Note that all activity on this question ceased when I mentioned the Solaris 10 patch 119966-02 four months ago. – Andrew Henle Apr 18 '19 at 21:18
  • when you get the gcc compiler installed by csw to compile code 'std::float' let me know because it does not accept it. compiler **error** == does not compile. – codeDr Apr 20 '19 at 21:55
  • 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 Apr 20 '19 at 23:43
  • The issue may be related to the [issue stated here](http://gcc.1065356.n8.nabble.com/the-mystery-of-math-h-in-lib-gcc-triple-name-gcc-version-include-fixed-td1524637.html). Their conclusion seem to be that there is a missmatch between the `math.h` file on the build and host machine. – Benjamin Christoffersen Mar 11 '21 at 06:14
  • The solution is to build gcc on the same machine as it is used. It fixed similar problems I had as [I describe here](https://github.com/r-hub/solarischeck/issues/8#issuecomment-796735501). – Benjamin Christoffersen Mar 11 '21 at 13:29