Opened 7 years ago

Last modified 6 years ago

#53226 assigned defect

gcc5 @5.4: error: 'std::log2' has not been declared

Reported by: noloader (Jeffrey Walton) Owned by: macports-tickets@…
Priority: Normal Milestone:
Component: ports Version: 2.3.5
Keywords: powerpc Cc: ryandesign (Ryan Carsten Schmidt), cooljeanius (Eric Gallager)
Port: gcc5

Description

I'm working on a PowerMac G5. It runs OS X 10.5.8. It has MacPorts installed for updated gear. The machine survives specifically for big-endian PowerPC testing.

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

Compiling a program which uses log2 under C++11 results in a compile error 'std::log2' has not been declared:

$ /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 );
               ^

MacPorts is version 2.3.5 and fully patched. GCC version string is:

$ /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.
...

Change History (8)

comment:1 Changed 7 years ago by noloader (Jeffrey Walton)

I found I could work around the issue with the following. I'm not sure its a good workaround, though. I think I'm supposed to avoid adding symbols to std namespace like this.

namespace std
{
   inline double log2(double d)
      {return ::log2(d);}
}

comment:2 Changed 7 years ago by ryandesign (Ryan Carsten Schmidt)

Cc: ryandesign added
Keywords: powerpc added; c++11 cmath log2 removed
Owner: set to mww@…
Port: gcc5 added; g++-mp-5 removed
Status: newassigned
Summary: PowerMac, GCC 5.4 and "error: 'std::log2' has not been declared"gcc5 @5.4: error: 'std::log2' has not been declared

I'm the one who has been updating the gcc ports for a few years, but I don't know C++ or the internals of gcc well enough to be able to help you with this. Markus is the maintainer, but he has been unresponsive for awhile. I suggest you test with gcc6 and gcc7. If the problem persists there, report the problem to the developers of gcc directly.

comment:3 Changed 7 years ago by kencu (Ken)

there is a slight difference in the way gcc work on 10.5 PPC, it appears.

On PPC, it works OK if you just leave the std:: part off:

#include <cmath>
#include <stdio.h>
int main(int argc, char* argv[])
{
    int i = 1000;
    double b = log2(i);
    printf("%f \n",b);

    double d = log2(2.3456789f);
    printf("%f \n",d);
    return 0;
}

$ g++ -std=c++11 math.cxx -o math
LeopardG5:mathtest $ ./math
9.965784 
1.230005

The same code on the intel machine I'm using to compare works with the std:: part on or off.

Right at the moment, I don't have gcc installed on my 10.5 intel machine to see if it's a 10.5 difference or an intel/ppc difference.

comment:4 Changed 7 years ago by noloader (Jeffrey Walton)

comment:5 Changed 7 years ago by kencu (Ken)

some more data - from an Intel 10.5 machine. Same issue on the Intel machine, and also same issue with clang++. So it's looking more like a 10.5 issue than anything else, at the moment - not specific to gcc, and not specific to PPC. The llrint and other similar missing definitions you noted are a recognized issue with systems < 10.7, btw, see <https://github.com/jeremyhu/libcxx/commit/720feba4874d4ca3131753dc31af127e3c509c36>

$ cat math.cxx
#include <cmath>
#include <stdio.h>
int main(int argc, char* argv[])
{
    int i = 1000;
    double b = std::log2(i);
    printf("%f \n",b);

    double d = std::log2(2.3456789f);
    printf("%f \n",d);
    return 0;
}
$ g++ --version
i686-apple-darwin9-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5555) (LLVM build 2064.3)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ -o math.intel math.cxx
math.cxx: In function ‘int main(int, char**)’:
math.cxx:6: error: ‘log2’ is not a member of ‘std’
math.cxx:9: error: ‘log2’ is not a member of ‘std’
$ clang++ --version
clang version 3.7.1 (tags/RELEASE_371/final)
Target: i686-apple-darwin9.8.0
Thread model: posix
$ clang++ -o math.intel math.cxx
math.cxx:6:16: error: no member named 'log2' in namespace 'std'; did you mean simply 'log2'?
    double b = std::log2(i);
               ^~~~~~~~~
               log2
/usr/include/architecture/i386/math.h:316:15: note: 'log2' declared here
extern double log2 ( double );
              ^
math.cxx:9:16: error: no member named 'log2' in namespace 'std'; did you mean simply 'log2'?
    double d = std::log2(2.3456789f);
               ^~~~~~~~~
               log2
/usr/include/architecture/i386/math.h:316:15: note: 'log2' declared here
extern double log2 ( double );
              ^
Last edited 7 years ago by kencu (Ken) (previous) (diff)

comment:6 Changed 7 years ago by noloader (Jeffrey Walton)

Thanks Ken. I passed on the libc++ commit to Jonathan Wakely in the GCC bug report. It should be very helpful to him if he decides to proceed.

comment:7 Changed 7 years ago by kurthindenburg (Kurt Hindenburg)

Owner: changed from mww@… to macports-tickets@…

comment:8 Changed 6 years ago by cooljeanius (Eric Gallager)

Cc: cooljeanius added
Note: See TracTickets for help on using tickets.