错误:"log2"不是"std"的成员 [英] error: 'log2' is not a member of 'std'

查看:476
本文介绍了错误:"log2"不是"std"的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我在这里看到的是什么.以下测试结果来自运行OS X 10.5.8的旧PowerMac G5.它仍然可以在大端PowerPC cpu下进行测试.编译器为GCC 5.4,由MacPorts提供.

下面是测试程序.编译它会导致错误 error: 'log2' is not a member of 'std' .

$ cat test.cxx
#include <cmath>
int main(int argc, char* argv[])
{
    double d = std::log2(2.3456789f);
    return 0;
}

根据 std :: log2()是扩展程序还是C ++标准?std::log2应该可用. >

为什么程序无法编译?


$ /opt/local/bin/g++-mp-5 --version
g++-mp-5 (MacPorts gcc5 5.4.0_0) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.

$ /opt/local/bin/g++-mp-5 -std=c++11 test.cxx -o test.exe
test.cxx: In function 'int main(int, char**)':
test.cxx:4:16: error: 'log2' is not a member of 'std'
     double d = std::log2(2.3456789f);
                ^
test.cxx:4:16: note: suggested alternative:
In file included from /usr/include/math.h:26:0,
                 from /opt/local/include/gcc5/c++/cmath:44,
                 from test.cxx:1:
/usr/include/architecture/ppc/math.h:431:15: note:   'log2'
 extern double log2( double );
               ^


这可能是由于旧硬件而引起的: C ++ 11 cmath函数不在带有Ncc的android NDK的std名称空间中,或者lang 3.4 .我意识到Android是一个不同的平台.


现在在MacPorts问题跟踪器中打开:问题53226:PowerMac,GCC 5.4和错误:'std :: log2'尚未声明" .

现在在GCC问题跟踪器中打开:问题79017:旧的PowerMac G5, MacPorts GCC 5.4,C ++ 11和尚未声明std :: log2"

解决方案

为什么程序无法编译?

位于以下位置的GCC报告:问题79017:旧的PowerMac G5,MacPorts GCC 5.4, C ++ 11和"std :: log2尚未声明" 从GCC开发人员那里得到了很好的评价.

根据 Jonathan Wakely以及以下程序的结果:

test.cxx:53:21: error: 'llrint' was not declared in this scope
llrint(0.0);

test.cxx:54:23: error: 'llrintf' was not declared in this scope
llrintf(0.0f);

test.cxx:55:23: error: 'llrintl' was not declared in this scope
llrintl(0.0l);

test.cxx:56:22: error: 'llround' was not declared in this scope
llround(0.0);

test.cxx:57:24: error: 'llroundf' was not declared in this scope
llroundf(0.0f);

test.cxx:58:24: error: 'llroundl' was not declared in this scope
llroundl(0.0l);   

由于缺少这六个功能,我们将处理所有C99数学 功能缺失.我们可以将支票分成两部分,所以我们 分别检查这些内容,这将允许其余的C99数学 库将导入到命名空间std.


#include <math.h>
int main() {
          typedef double_t  my_double_t;
          typedef float_t   my_float_t;
          acosh(0.0);
          acoshf(0.0f);
          acoshl(0.0l);
          asinh(0.0);
          asinhf(0.0f);
          asinhl(0.0l);
          atanh(0.0);
          atanhf(0.0f);
          atanhl(0.0l);
          cbrt(0.0);
          cbrtf(0.0f);
          cbrtl(0.0l);
          copysign(0.0, 0.0);
          copysignf(0.0f, 0.0f);
          copysignl(0.0l, 0.0l);
          erf(0.0);
          erff(0.0f);
          erfl(0.0l);
          erfc(0.0);
          erfcf(0.0f);
          erfcl(0.0l);
          exp2(0.0);
          exp2f(0.0f);
          exp2l(0.0l);
          expm1(0.0);
          expm1f(0.0f);
          expm1l(0.0l);
          fdim(0.0, 0.0);
          fdimf(0.0f, 0.0f);
          fdiml(0.0l, 0.0l);
          fma(0.0, 0.0, 0.0);
          fmaf(0.0f, 0.0f, 0.0f);
          fmal(0.0l, 0.0l, 0.0l);
          fmax(0.0, 0.0);
          fmaxf(0.0f, 0.0f);
          fmaxl(0.0l, 0.0l);
          fmin(0.0, 0.0);
          fminf(0.0f, 0.0f);
          fminl(0.0l, 0.0l);
          hypot(0.0, 0.0);
          hypotf(0.0f, 0.0f);
          hypotl(0.0l, 0.0l);
          ilogb(0.0);
          ilogbf(0.0f);
          ilogbl(0.0l);
          lgamma(0.0);
          lgammaf(0.0f);
          lgammal(0.0l);
          llrint(0.0);
          llrintf(0.0f);
          llrintl(0.0l);
          llround(0.0);
          llroundf(0.0f);
          llroundl(0.0l);
          log1p(0.0);
          log1pf(0.0f);
          log1pl(0.0l);
          log2(0.0);
          log2f(0.0f);
          log2l(0.0l);
          logb(0.0);
          logbf(0.0f);
          logbl(0.0l);
          lrint(0.0);
          lrintf(0.0f);
          lrintl(0.0l);
          lround(0.0);
          lroundf(0.0f);
          lroundl(0.0l);
          nan(0);
          nanf(0);
          nanl(0);
          nearbyint(0.0);
          nearbyintf(0.0f);
          nearbyintl(0.0l);
          nextafter(0.0, 0.0);
          nextafterf(0.0f, 0.0f);
          nextafterl(0.0l, 0.0l);
          nexttoward(0.0, 0.0);
          nexttowardf(0.0f, 0.0f);
          nexttowardl(0.0l, 0.0l);
          remainder(0.0, 0.0);
          remainderf(0.0f, 0.0f);
          remainderl(0.0l, 0.0l);
          remquo(0.0, 0.0, 0);
          remquof(0.0f, 0.0f, 0);
          remquol(0.0l, 0.0l, 0);
          rint(0.0);
          rintf(0.0f);
          rintl(0.0l);
          round(0.0);
          roundf(0.0f);
          roundl(0.0l);
          scalbln(0.0, 0l);
          scalblnf(0.0f, 0l);
          scalblnl(0.0l, 0l);
          scalbn(0.0, 0);
          scalbnf(0.0f, 0);
          scalbnl(0.0l, 0);
          tgamma(0.0);
          tgammaf(0.0f);
          tgammal(0.0l);
          trunc(0.0);
          truncf(0.0f);
          truncl(0.0l);
          return 0;
}

I'm not sure what I am seeing here. The test results below are from an old PowerMac G5 running OS X 10.5.8. Its still around for testing under the big-endian PowerPC cpu. The compiler is GCC 5.4, and its provided by MacPorts.

The test program is below. Compiling it results in an error error: 'log2' is not a member of 'std'.

$ cat test.cxx
#include <cmath>
int main(int argc, char* argv[])
{
    double d = std::log2(2.3456789f);
    return 0;
}

According to Is std::log2() an extension or C++ standard?, std::log2 should be available.

Why is the program failing to compile?


$ /opt/local/bin/g++-mp-5 --version
g++-mp-5 (MacPorts gcc5 5.4.0_0) 5.4.0
Copyright (C) 2015 Free Software Foundation, Inc.

$ /opt/local/bin/g++-mp-5 -std=c++11 test.cxx -o test.exe
test.cxx: In function 'int main(int, char**)':
test.cxx:4:16: error: 'log2' is not a member of 'std'
     double d = std::log2(2.3456789f);
                ^
test.cxx:4:16: note: suggested alternative:
In file included from /usr/include/math.h:26:0,
                 from /opt/local/include/gcc5/c++/cmath:44,
                 from test.cxx:1:
/usr/include/architecture/ppc/math.h:431:15: note:   'log2'
 extern double log2( double );
               ^


This may be related because of the old hardware: C++11 cmath functions not in std namespace for android NDK w/gcc-4.8 or clang 3.4. I realize Android is a different platform.


Now open in the MacPorts issue tracker: Issue 53226: PowerMac, GCC 5.4 and "error: 'std::log2' has not been declared".

Now open in the GCC issue tracker: Issue 79017: Old PowerMac G5, MacPorts GCC 5.4, C++11 and "std::log2 has not been declared"

解决方案

Why is the program failing to compile?

The GCC report at Issue 79017: Old PowerMac G5, MacPorts GCC 5.4, C++11 and "std::log2 has not been declared" got some good comments from the GCC devs.

According to Jonathan Wakely and the results of the program below:

test.cxx:53:21: error: 'llrint' was not declared in this scope
llrint(0.0);

test.cxx:54:23: error: 'llrintf' was not declared in this scope
llrintf(0.0f);

test.cxx:55:23: error: 'llrintl' was not declared in this scope
llrintl(0.0l);

test.cxx:56:22: error: 'llround' was not declared in this scope
llround(0.0);

test.cxx:57:24: error: 'llroundf' was not declared in this scope
llroundf(0.0f);

test.cxx:58:24: error: 'llroundl' was not declared in this scope
llroundl(0.0l);   

Because these six functions are missing we treat all C99 math functions as missing. We could split the checks into two pieces, so we check for these separately, which would allow the rest of the C99 math library to be imported into namespace std.


#include <math.h>
int main() {
          typedef double_t  my_double_t;
          typedef float_t   my_float_t;
          acosh(0.0);
          acoshf(0.0f);
          acoshl(0.0l);
          asinh(0.0);
          asinhf(0.0f);
          asinhl(0.0l);
          atanh(0.0);
          atanhf(0.0f);
          atanhl(0.0l);
          cbrt(0.0);
          cbrtf(0.0f);
          cbrtl(0.0l);
          copysign(0.0, 0.0);
          copysignf(0.0f, 0.0f);
          copysignl(0.0l, 0.0l);
          erf(0.0);
          erff(0.0f);
          erfl(0.0l);
          erfc(0.0);
          erfcf(0.0f);
          erfcl(0.0l);
          exp2(0.0);
          exp2f(0.0f);
          exp2l(0.0l);
          expm1(0.0);
          expm1f(0.0f);
          expm1l(0.0l);
          fdim(0.0, 0.0);
          fdimf(0.0f, 0.0f);
          fdiml(0.0l, 0.0l);
          fma(0.0, 0.0, 0.0);
          fmaf(0.0f, 0.0f, 0.0f);
          fmal(0.0l, 0.0l, 0.0l);
          fmax(0.0, 0.0);
          fmaxf(0.0f, 0.0f);
          fmaxl(0.0l, 0.0l);
          fmin(0.0, 0.0);
          fminf(0.0f, 0.0f);
          fminl(0.0l, 0.0l);
          hypot(0.0, 0.0);
          hypotf(0.0f, 0.0f);
          hypotl(0.0l, 0.0l);
          ilogb(0.0);
          ilogbf(0.0f);
          ilogbl(0.0l);
          lgamma(0.0);
          lgammaf(0.0f);
          lgammal(0.0l);
          llrint(0.0);
          llrintf(0.0f);
          llrintl(0.0l);
          llround(0.0);
          llroundf(0.0f);
          llroundl(0.0l);
          log1p(0.0);
          log1pf(0.0f);
          log1pl(0.0l);
          log2(0.0);
          log2f(0.0f);
          log2l(0.0l);
          logb(0.0);
          logbf(0.0f);
          logbl(0.0l);
          lrint(0.0);
          lrintf(0.0f);
          lrintl(0.0l);
          lround(0.0);
          lroundf(0.0f);
          lroundl(0.0l);
          nan(0);
          nanf(0);
          nanl(0);
          nearbyint(0.0);
          nearbyintf(0.0f);
          nearbyintl(0.0l);
          nextafter(0.0, 0.0);
          nextafterf(0.0f, 0.0f);
          nextafterl(0.0l, 0.0l);
          nexttoward(0.0, 0.0);
          nexttowardf(0.0f, 0.0f);
          nexttowardl(0.0l, 0.0l);
          remainder(0.0, 0.0);
          remainderf(0.0f, 0.0f);
          remainderl(0.0l, 0.0l);
          remquo(0.0, 0.0, 0);
          remquof(0.0f, 0.0f, 0);
          remquol(0.0l, 0.0l, 0);
          rint(0.0);
          rintf(0.0f);
          rintl(0.0l);
          round(0.0);
          roundf(0.0f);
          roundl(0.0l);
          scalbln(0.0, 0l);
          scalblnf(0.0f, 0l);
          scalblnl(0.0l, 0l);
          scalbn(0.0, 0);
          scalbnf(0.0f, 0);
          scalbnl(0.0l, 0);
          tgamma(0.0);
          tgammaf(0.0f);
          tgammal(0.0l);
          trunc(0.0);
          truncf(0.0f);
          truncl(0.0l);
          return 0;
}

这篇关于错误:"log2"不是"std"的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆