On 02 Jun 2014, at 15:49, h...@sdf.org wrote: > Lowell Gilbert <freebsd-ports-lo...@be-well.ilk.org> writes: > >> h...@sdf.org writes: >> >>> I'm trying to compile OpenCog [1] using g++47, but get an error about >>> missing std::stoi. >>> >>> I have attached a micro-example [2] that generates the same error, if I >>> try to compile it with: >>> >>> % g++47 -std=c++11 s.cc >>> s.cc: In function 'int main()': >>> s.cc:8:13: error: 'stoi' is not a member of 'std' >>> >>> >>> There are no problems neither with clang nor with g++ on Debian: >>> >>> % clang++ -std=c++11 s.cc >>> >>> >>> >>> What am I missing? >> >> An old libc++ bug in gcc. >> >> You need a newer compiler. > > I tried with gcc49 and it seem to have the same problem.
This is because gcc's basic_string.h (from gcc 4.8 and higher) has the following conditional for declaring std::stoi() and friends: #if ((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) Unfortunately libstdc++'s configure script thinks FreeBSD does not have proper C99 support, so it undefines _GLIBCXX_USE_C99, see /usr/local/lib/gcc48/include/c++/i386-portbld-freebsd11.0/bits/c++config.h around line 1238: /* Define if C99 functions or macros from <wchar.h>, <math.h>, <complex.h>, <stdio.h>, and <stdlib.h> can be used or exposed. */ /* #undef _GLIBCXX_USE_C99 */ This is also the case for the copy of c++config.h in the base system. The libstdc++ configure script says the following (excerpted): ... configure:16721: checking for ISO C99 support in <complex.h> configure:16852: g++48 -o conftest -std=c++98 -fno-exceptions conftest.cpp -lm >&5 conftest.cpp: In function 'int main()': conftest.cpp:52:19: error: 'clogf' was not declared in this scope tmpf = clogf(tmpf); ^ conftest.cpp:58:25: error: 'cpowf' was not declared in this scope tmpf = cpowf(tmpf, tmpf); ^ conftest.cpp:65:18: error: 'clog' was not declared in this scope tmpd = clog(tmpd); ^ conftest.cpp:71:24: error: 'cpow' was not declared in this scope tmpd = cpow(tmpd, tmpd); ^ conftest.cpp:75:21: error: 'ccosl' was not declared in this scope tmpld = ccosl(tmpld); ^ conftest.cpp:76:22: error: 'ccoshl' was not declared in this scope tmpld = ccoshl(tmpld); ^ conftest.cpp:77:21: error: 'cexpl' was not declared in this scope tmpld = cexpl(tmpld); ^ conftest.cpp:78:21: error: 'clogl' was not declared in this scope tmpld = clogl(tmpld); ^ conftest.cpp:79:21: error: 'csinl' was not declared in this scope tmpld = csinl(tmpld); ^ conftest.cpp:80:22: error: 'csinhl' was not declared in this scope tmpld = csinhl(tmpld); ^ conftest.cpp:82:21: error: 'ctanl' was not declared in this scope tmpld = ctanl(tmpld); ^ conftest.cpp:83:22: error: 'ctanhl' was not declared in this scope tmpld = ctanhl(tmpld); ^ conftest.cpp:84:28: error: 'cpowl' was not declared in this scope tmpld = cpowl(tmpld, tmpld); ^ ... configure:16861: result: no configure:16870: checking for ISO C99 support in <stdio.h> configure:16927: g++48 -o conftest -std=c++98 -fno-exceptions conftest.cpp -lm >&5 conftest.cpp: In function 'int main()': conftest.cpp:47:23: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings] snprintf("12", 0, "%i"); ^ configure:16927: $? = 0 configure:16938: result: yes configure:16942: checking for ISO C99 support in <stdlib.h> configure:17011: g++48 -o conftest -std=c++98 -fno-exceptions conftest.cpp -lm >&5 conftest.cpp:38:7: error: 'lldiv_t' does not name a type lldiv_t mydivt; ^ conftest.cpp: In function 'int main()': conftest.cpp:45:35: error: 'strtoll' was not declared in this scope ll = strtoll("gnu", &tmp, 10); ^ conftest.cpp:46:36: error: 'strtoull' was not declared in this scope ll = strtoull("gnu", &tmp, 10); ^ conftest.cpp:47:20: error: 'llabs' was not declared in this scope ll = llabs(10); ^ conftest.cpp:48:7: error: 'mydivt' was not declared in this scope mydivt = lldiv(10,1); ^ conftest.cpp:48:26: error: 'lldiv' was not declared in this scope mydivt = lldiv(10,1); ^ conftest.cpp:51:22: error: 'atoll' was not declared in this scope ll = atoll("10"); ^ ... configure:17022: result: no configure:17029: checking for ISO C99 support in <wchar.h> configure:17049: g++48 -c -std=c++98 -fno-exceptions conftest.cpp >&5 conftest.cpp:38:17: error: '::wcstoll' has not been declared using ::wcstoll; ^ conftest.cpp:39:17: error: '::wcstoull' has not been declared using ::wcstoull; ^ ... configure:17182: checking for fully enabled ISO C99 support configure:17184: result: no The end result is that quite a lot of functionality in libstdc++'s headers is being disabled because of this. My advice is to use libc++ for now, which has no such problems, and can also be used with gcc 4.8 or higher. -Dimitry
signature.asc
Description: Message signed with OpenPGP using GPGMail