This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Localization with libstdc++ fails on FreeBSD
- From: Sashi Asokarajan <sashi at gmx dot de>
- To: libstdc++ at gcc dot gnu dot org
- Date: Sun, 27 Apr 2008 13:54:48 +0200
- Subject: Localization with libstdc++ fails on FreeBSD
Hello,
if I try to instantiate std::locale for locales other than "C",
it aborts with an exception in FreeBSD 7.0 !
What I found out so far is, that FreeBSD is probably 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
My GCC reports:
> gcc -v
Using built-in specs.
Target: i386-undermydesk-freebsd
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 4.2.1 20070719 [FreeBSD]
on my FreeBSD 7.0-RELEASE system.
My $LANG is set to de_DE.UTF-8 (via login.conf).
locale -a|grep de_DE reports:
de_DE.ISO8859-1
de_DE.ISO8859-15
de_DE.UTF-8
Here's a C++ code you may want to try (compile with CC <filename.cc>).
It works well with "setenv LANG C", but fails if LANG=de_DE.UTF-8 (or any other) !
//---------------------------------------------------
#include <locale>
#include <iostream>
#include <clocale>
int main()
{
using std::cout;
using std::endl;
// C L10n
const char* const lstr = std::setlocale(LC_ALL, "");
cout << "C setlocale()\nresult=";
cout << ( lstr ? lstr : "0" ) << "\n" << endl;
// C++ L10n
cout << "C++ std::locale" << endl;
std::locale loc("");
cout << "std::locale loc=" << loc.name() << endl;
}
//---------------------------------------------------
Output (set $LANG to de_DE.UTF-8 and run with ./a.out):
-------------------------------------------------------------------
C setlocale()
result=de_DE.UTF-8
C++ std::locale
terminate called after throwing an instance of 'std::runtime_error'
what(): locale::facet::_S_create_c_locale name not valid
Abort (core dumped)
-------------------------------------------------------------------
Why does the "darwin" (which is generic) model apply to the FreeBSD OS?
(I guess C++ localization will also fail on MacOS X too.)
Thanks in advance for any ideas.
--
Sashi Asokarajan