recently I stepped over Strotrup's TC++PL (third ed.) Chapter D.1
where the localization support of the C++ stdlib is explained.
[ http://www.research.att.com/~bs/3rd_loc.pdf ]
Unfortunately the constructor fails if I try to instantiate std::locale
for locales other than C or POSIX.
With (only) LANG="de.DE.UTF-8" set in ENV the following code thows an exception:
std::locale loc("");
and std::setlocale(LC_ALL, ""); works fine?!
My GCC Version is "gcc (GCC) 3.4.6 [FreeBSD] 20060305" and I'm
using FreeBSD 6.2.
Here's my example code:
#include <clocale>
#include <iostream>
int main()
{
using std::cout;
using std::endl;
const char* const lstr = std::setlocale(LC_ALL, "");
if (lstr)
cout << "lstr=" << lstr << endl;
else
cout << "lstr=NULL" << endl;
std::locale loc("");
cout << "std::locale loc=" << loc.name() << endl;
}
Output:
lstr=de_DE.UTF-8
terminate called after throwing an instance of 'std::runtime_error'
what(): locale::facet::_S_create_c_locale name not valid
Abort (core dumped)
Does anyone have similar problems ? What am I doing wrong ?
Is the libstdc++ incomplete on my platform?
Sashi
> With (only) LANG="de.DE.UTF-8"
I assume you really mean "de_DE.UTF-8", not what you typed.
> lstr=de_DE.UTF-8
> terminate called after throwing an instance of 'std::runtime_error'
> what(): locale::facet::_S_create_c_locale name not valid
> Abort (core dumped)
Works fine here (Linux Fedora Core 2).
What do you have in /usr/lib/locale/de_DE.* ?
> Does anyone have similar problems ? What am I doing wrong ?
> Is the libstdc++ incomplete on my platform?
I don't think this has anything to do with libstdc++.
More likely your de_DE* locale packages aren't complete.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
>> lstr=de_DE.UTF-8
this is the result of std::setlocale(LC_ALL, "");
(NOTE: I haven't set $LC_ALL, only $LANG !)
>> terminate called after throwing an instance of 'std::runtime_error'
>> what(): locale::facet::_S_create_c_locale name not valid
>> Abort (core dumped)
and this the failure of std::locale loc("");
> Works fine here (Linux Fedora Core 2).
Yes, I tested the code on Linux and it went well. OS X users my have
the same problem?! I'm interested in writing a portable code, for
that reason I'm trying to understand the platform specific dependencies
of std::locale.
> What do you have in /usr/lib/locale/de_DE.* ?
the locales are installed correctly:
$ locale -a | grep -i de_DE
de_DE.ISO8859-1
de_DE.ISO8859-15
de_DE.UTF-8
>> Does anyone have similar problems ? What am I doing wrong ?
>> Is the libstdc++ incomplete on my platform?
anyone
> I don't think this has anything to do with libstdc++.
> More likely your de_DE* locale packages aren't complete.
I'm not sure. std::setlocale() works fine?!
I also found out, that if I additionally set LC_ALL="de_DE.UTF-8"
both (c & c++ locale calls) fail!
any ideas ?
thanks.
The automatic locale detection in the libstdc++ configure script says following:
5801 # Probe for locale model to use if none specified.
5802 # Default to "generic".
5803 if test $enable_clocale_flag = auto; then
5804 case ${target_os} in
5805 linux* | gnu* | kfreebsd*-gnu | knetbsd*-gnu)
5806 enable_clocale_flag=gnu
5807 ;;
5808 darwin* | freebsd*)
5809 enable_clocale_flag=darwin
5810 ;;
5811 *)
5812 enable_clocale_flag=generic
5813 ;;
5814 esac
5815 fi
Why does the "darwin" (which is generic) model apply to the FreeBSD?
(I guess C++ localization will fail on MacOS X too.)
--
Sashi Asokarajan
Hi Sashi,
I have the same problem ...
I filed a ticket with macport, but I was curious to know if the --
enable-clocale does any good ...
Best, Dirk
The FreeBSD system sources comes already configure'd. So I downloaded
GCC and tried to configure/build it with --enable-clocale.
Unfortunately it failed and since then I haven't had the chance to find out why.
--
Sashi