3

I have the following code...

// My.h
#include <string>
....

// My.cpp
#include "My.h"
...
errMsg = "X value [too low]: " + std::to_string(xInVal);

But when I compile like...

//setup.py
extra_compile_args =['-std=c++11']

//console output
gcc -Wno-unused-result -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/ports/python3/python3-3.4.3-1.x86_64/build=/usr/src/debug/python3-3.4.3-1 -fdebug-prefix-map=/usr/src/ports/python3/python3-3.4.3-1.x86_64/src/Python-3.4.3=/usr/src/debug/python3-3.4.3-1 -I./My -c ./My.cpp -o build/temp.cygwin-2.2.1-x86_64-3.4/./My.o -std=c++11

I get the following error....

 error: ‘to_string’ is not a member of ‘std’
   errMsg = "X value [too low]: " + std::to_string(xInVal);

What am I missing how do I use to_string in this way?

Jackie
  • 21,969
  • 32
  • 147
  • 289
  • possible dupe http://stackoverflow.com/questions/12975341/to-string-is-not-a-member-of-std-says-so-g – Jackie Dec 29 '15 at 21:09
  • 1
    What version of GCC are you using (`gcc --version`) ? – Martin Bonner supports Monica Dec 29 '15 at 21:14
  • 3
    Actually it still doesn't work even on Cygwin GCC 5.2.0 + stdlibc++ 5.2.0. I was very surprised. @Jackie you might implement it yourself, it's not a big deal, or to switch to another Windows toolchain: MSYS + MinGW-w64 (have it fixed), Visual studio (it is not that bad as it used to be and they have standalone toolchain now, that is without IDE), Clang/C2 (clang frontend + microsoft codegen), Intel etc. The only problem is if your app uses something like autotools or Unix-specific headers/libs. – Ivan Aksamentov - Drop Dec 29 '15 at 21:25
  • @Drop Thanks I tried to look up how to patch it but I am not having much luck. If I fall back to a Unix VM it should work ok right (or at least not have these problems). Guess I will have to bring myself to learn one of those other toolchains. – Jackie Dec 29 '15 at 21:36

1 Answers1

0

From the CYGWIN headers, it looks like for C++11 these are not defined unless _GLIBCXX_USE_C99 is defined They are enclosed in this if:

#if __cplusplus >= 201103L && defined(_GLIBCXX_USE_C99)

I tried defining _GLIBCXX_USE_C99 but that didn't work for my project. You can try defining it before you use the string header.

I recently had a similar issue with C++11 on CYGWIN related to __STRICT_ANSI__

Yasser Asmi
  • 1,150
  • 2
  • 12
  • 27