This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Question on enabling c++ to_string to arm-none-eabi target
- From: Terry Guo <flameroc at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org
- Cc: joey dot ye at arm dot com
- Date: Thu, 31 Oct 2013 18:10:58 +0800
- Subject: Question on enabling c++ to_string to arm-none-eabi target
- Authentication-results: sourceware.org; auth=none
Hi there,
I just cross build a tool chain using latest trunk code on x86 for
arm-none-eabi. The C library is Newlib trunk. When compile below case:
#include <string>
int main()
{
std::to_string(0);
return 0;
}
with command "arm-none-eabi-g++ -mthumb -mcpu=cortex-m4 -std=c++11
-S c++_to_string.cc -O2", I got errors:
c++_to_string.cc: In function 'int main()':
c++_to_string.cc:5:5: error: 'to_string' is not a member of 'std'
std::to_string(0);
^
I then did some search and found it is because the macro
_GLIBCXX_USE_C99 isn't defined in H file
arm-none-eabi/include/c++/4.9.0/arm-none-eabi/bits/c++config.h. To get
this macro defined, below piece of code needs to be successfully
compiled during the configuration of libstdc++-v3:
| #include <stdio.h>
| #include <stdarg.h>
| void foo(char* fmt, ...)
| {
| va_list args; va_start(args, fmt);
| vfscanf(stderr, "%i", args);
| vscanf("%i", args);
| vsnprintf(fmt, 0, "%i", args);
| vsscanf(fmt, "%i", args);
| }
| int
| main ()
| {
| snprintf("12", 0, "%i");
| ;
| return 0;
| }
The stdio.h from Newlib defines vscanf function as:
#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 199901L)
int _EXFUN(vscanf, (const char *, __VALIST)
_ATTRIBUTE ((__format__ (__scanf__, 1, 0))));
#endif
And the libstdc++-v3 configuration always uses option -std=c++98 to
compile above code, this option indicate the define of
__STRICT_ANSI__. So always fail to compile above code with error
message:
conftest.cpp:36:19: error: 'vscanf' was not declared in this scope
vscanf("%i", args);
Finally failing to compile the conftest.cpp causes the disable of c++
to_string function. So what should I do to let those conftest.cpp
pass? By changing option from -std=c++98 to -std=gnu++98 or removing
the IF macros from stdio.h? Please help. Thanks in advance.
BR,
Terry