Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Jun 2014 21:59:56 +0200
From:      Dimitry Andric <dim@FreeBSD.org>
To:        hhh@sdf.org
Cc:        Lowell Gilbert <freebsd-ports-local@be-well.ilk.org>, freebsd-ports@freebsd.org
Subject:   Re: g++ cannot find std::stoi
Message-ID:  <3404EC6D-277F-4607-AD5B-33B60C4F5C1E@FreeBSD.org>
In-Reply-To: <87fvjnifpv.fsf@gmail.com>
References:  <874n09tr87.fsf@gmail.com> <44k3942y0w.fsf@be-well.ilk.org> <87fvjnifpv.fsf@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--Apple-Mail=_654A7955-7120-4F9F-B349-9EC73219C5E4
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=us-ascii

On 02 Jun 2014, at 15:49, hhh@sdf.org wrote:
> Lowell Gilbert <freebsd-ports-local@be-well.ilk.org> writes:
>=20
>> hhh@sdf.org writes:
>>=20
>>> I'm trying to compile OpenCog [1] using g++47, but get an error =
about
>>> missing std::stoi.
>>>=20
>>> I have attached a micro-example [2] that generates the same error, =
if I
>>> try to compile it with:
>>>=20
>>> % g++47 -std=3Dc++11 s.cc
>>> s.cc: In function 'int main()':
>>> s.cc:8:13: error: 'stoi' is not a member of 'std'
>>>=20
>>>=20
>>> There are no problems neither with clang nor with g++ on Debian:
>>>=20
>>> % clang++ -std=3Dc++11 s.cc
>>>=20
>>>=20
>>>=20
>>> What am I missing?
>>=20
>> An old libc++ bug in gcc.
>>=20
>> You need a newer compiler.
>=20
> 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 >=3D 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=3Dc++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 =3D clogf(tmpf);
                   ^
conftest.cpp:58:25: error: 'cpowf' was not declared in this scope
  tmpf =3D cpowf(tmpf, tmpf);
                         ^
conftest.cpp:65:18: error: 'clog' was not declared in this scope
  tmpd =3D clog(tmpd);
                  ^
conftest.cpp:71:24: error: 'cpow' was not declared in this scope
  tmpd =3D cpow(tmpd, tmpd);
                        ^
conftest.cpp:75:21: error: 'ccosl' was not declared in this scope
  tmpld =3D ccosl(tmpld);
                     ^
conftest.cpp:76:22: error: 'ccoshl' was not declared in this scope
  tmpld =3D ccoshl(tmpld);
                      ^
conftest.cpp:77:21: error: 'cexpl' was not declared in this scope
  tmpld =3D cexpl(tmpld);
                     ^
conftest.cpp:78:21: error: 'clogl' was not declared in this scope
  tmpld =3D clogl(tmpld);
                     ^
conftest.cpp:79:21: error: 'csinl' was not declared in this scope
  tmpld =3D csinl(tmpld);
                     ^
conftest.cpp:80:22: error: 'csinhl' was not declared in this scope
  tmpld =3D csinhl(tmpld);
                      ^
conftest.cpp:82:21: error: 'ctanl' was not declared in this scope
  tmpld =3D ctanl(tmpld);
                     ^
conftest.cpp:83:22: error: 'ctanhl' was not declared in this scope
  tmpld =3D ctanhl(tmpld);
                      ^
conftest.cpp:84:28: error: 'cpowl' was not declared in this scope
  tmpld =3D cpowl(tmpld, tmpld);
                            ^
...
configure:16861: result: no
configure:16870: checking for ISO C99 support in <stdio.h>
configure:16927: g++48 -o conftest  -std=3Dc++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: $? =3D 0
configure:16938: result: yes
configure:16942: checking for ISO C99 support in <stdlib.h>
configure:17011: g++48 -o conftest  -std=3Dc++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 =3D strtoll("gnu", &tmp, 10);
                                   ^
conftest.cpp:46:36: error: 'strtoull' was not declared in this scope
       ll =3D strtoull("gnu", &tmp, 10);
                                    ^
conftest.cpp:47:20: error: 'llabs' was not declared in this scope
       ll =3D llabs(10);
                    ^
conftest.cpp:48:7: error: 'mydivt' was not declared in this scope
       mydivt =3D lldiv(10,1);
       ^
conftest.cpp:48:26: error: 'lldiv' was not declared in this scope
       mydivt =3D lldiv(10,1);
                          ^
conftest.cpp:51:22: error: 'atoll' was not declared in this scope
       ll =3D atoll("10");
                      ^
...
configure:17022: result: no
configure:17029: checking for ISO C99 support in <wchar.h>
configure:17049: g++48 -c  -std=3Dc++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


--Apple-Mail=_654A7955-7120-4F9F-B349-9EC73219C5E4
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename=signature.asc
Content-Type: application/pgp-signature;
	name=signature.asc
Content-Description: Message signed with OpenPGP using GPGMail

-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)

iEYEARECAAYFAlOM18MACgkQsF6jCi4glqM1jACfU65bdxF/hO+QqnQ3BbNbqDsK
9QwAn1vJ37eUboxzht1EVPrjV7xBhN4b
=dE1z
-----END PGP SIGNATURE-----

--Apple-Mail=_654A7955-7120-4F9F-B349-9EC73219C5E4--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3404EC6D-277F-4607-AD5B-33B60C4F5C1E>