Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cygwin support for C++11 in g++4.9.2

Tags:

c++

c++11

cygwin

I am trying to test some C++11 code on Windows 7 under cygwin, and am getting compiling errors for functions that are defined starting with C++11, such as std::log2 and std::round. I am compiling with g++ -std=c++11 test.cpp, using gcc 4.9.2. Here is some minimal example that fails to compile:

#include <cmath>
#include <iostream>

int main()
{
        auto x = std::log2(10);
        std::cout << x << std::endl;
}

error:

g++ -std=c++11 test.cpp
test.cpp: In function ‘int main()’:
test.cpp:5:11: error: ‘log2’ is not a member of ‘std’
  auto x = std::log2(10);
           ^
test.cpp:5:11: note: suggested alternative:
In file included from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/cmath:44:0,
                 from test.cpp:1:
/usr/include/math.h:305:15: note:   ‘log2’
 extern double log2 _PARAMS((double));

Is this a known bug in cygwin's g++ porting? The code above works fine on any Linux/UNIX flavour supporting C++11.

like image 370
vsoftco Avatar asked Oct 20 '22 16:10

vsoftco


1 Answers

The issue seems to be a bug related to cygwin implementation, thanks to Shafik Yaghmour for pointing it out.

The issue is now fixed via a patch for <cmath>, also at the link provided above.

like image 117
vsoftco Avatar answered Oct 30 '22 15:10

vsoftco