c++ - 无法在 Solaris 10 上使用 GCC 5.5 包含 cmath
问题描述
我正在尝试使用 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;
我按照此处给出的说明安装了 GCC 5.5 。
解决方案
我发现了同样的错误。在标题/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;
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.
@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 代码没有问题。
推荐阅读
- stripe-payments - 如何处理向客户收取款项的SaaS经销商?
- c++ - 使用 libcxx 和 std::atomic,如何通过默认构造函数清除 std::atomic_flag?
- reactjs - 使用 redux 和 webpack 反应 SSR 优化后 Gtmetrix 分数不会增加
- javascript - 从 Python 脚本获取输入到 Node.js Telegram Bot
- python-3.x - tf.tape.gradient() 返回无
- sql - 概括 CASE 语句(结果列的动态名称?)
- python - 从 csv 数据创建树结构以用于折叠菜单
- c++ - 辅助类型别名与继承
- python - 使用 selenium 获取 img 标签的 alt 属性值
- python-3.x - python38.dll 在 windows 10 中被自动删除