Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

std::locale ctor fails (L10n with C++)

368 views
Skip to first unread message

Sashi Asokarajan

unread,
Mar 29, 2008, 1:42:08 PM3/29/08
to
Hello,

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

Paul Pluzhnikov

unread,
Mar 29, 2008, 8:18:01 PM3/29/08
to
Sashi Asokarajan <sa...@gmx.de> writes:

> 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.

Sashi Asokarajan

unread,
Mar 30, 2008, 5:57:08 AM3/30/08
to
Paul Pluzhnikov wrote:
> Sashi Asokarajan <sa...@gmx.de> writes:
>
>> With (only) LANG="de.DE.UTF-8"
>
> I assume you really mean "de_DE.UTF-8", not what you typed.
oops sorry. it's set to de_DE.UTF-8

>> 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.

sashi.vcf

Sashi Asokarajan

unread,
Apr 27, 2008, 7:20:24 AM4/27/08
to
What I found out so far is, that FreeBSD is configured with the "darwin"
locale model. There is a configure option named --enable-clocale for libstdc++,
which is used to set the locale model.
The default (option omitted) is to autodetect for the target_os.

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

diddek

unread,
Jun 17, 2008, 2:53:18 PM6/17/08
to

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

Sashi

unread,
Jul 15, 2008, 2:50:38 PM7/15/08
to
diddek wrote:
> I filed a ticket with macport, but I was curious to know if the --
> enable-clocale does any good ...
Sorry, but I stopped playing with locales (for now), because it's
heavily platform dependent (BSD/Linux vs. Solaris vs. Win32).

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

0 new messages