I have a C++ application that I am porting to MacOSX (specifically, 10.6). The app makes heavy use of the C++ standard library and boost. I recently observed some breakage i
I have encountered this problem very recently on Ubuntu 14.04 LTS and on a Raspberry Pi running the latest Raspbian Wheezy.
It has nothing to do with OS X, rather with a combination of G++ and Boost (at least up to V1.55) and the default locale settings on certain platforms. There are Boost bug tickets sort of related to this issue, see ticket #4688 and ticket #5928.
My "solution" was first to do some extra locale setup, as suggested by this AskUbuntu posting:
sudo locale-gen en_US en_US.UTF-8
sudo dpkg-reconfigure locales
But then, I also had to make sure that the environment variable LC_ALL
is set to the value of LANG
(it is advisable to put this in your .profile
):
export LC_ALL=$LANG
In my case I use the locale en_US.UTF-8
.
Final remark: the OP said "This program fails when I run this through g++". I understand that this thread was started in 2009, but today there is absolutely no need to use GCC or G++ on the Mac, the much better LLVM/Clang compiler suite is available from Apple free of charge, see the XCode home page.
I had the same problem, checked LANG and LC_MESSAGES and they are not set when you lunch the application through Finder, so the following lines saved the day:
unset("LANG");
unset("LC_MESSAGES");
Ok I don't have an answer for you, but I have some clues:
_S_create_c_locale
. What I found is on line 143 of config/locale/generic/c_locale.cc. The comment there says "Currently, the generic model only supports the "C" locale." That's not promising. In fact if I do LANG=C
the runtime error goes away, but any other value for LANG
I try causes the same error, regardless of what arguments I give to the locale
constructor. (I tried locale::classic()
, "C", "", and the default). This is true as far back as GCC 4.0None of this tells you why the default locale on 10.6 wouldn't work with std::locale
but it does suggest a workaround, which is to set LANG=C
before running the program.
The situation is still the same. But some functionality may be gained by
setlocale( LC_ALL, "" );
This gets you UTF-8 coding on wide iostream
s but not money formatting, for my two data points.
locale::global( locale( "" ) );
should be equivalent, but it crashes if subsequently run in the very same program.
The _S_create_c_locale
exception seems to indicate some sort of misconfiguration: check that whatever your LC_ALL
or LANG
environment variable is set to, exists in the output of locale -a
.
$ env LC_ALL=xx_YY ./test terminate called after throwing an instance of 'std::runtime_error' what(): locale::facet::_S_create_c_locale name not valid Aborted $ env LC_ALL=C ./test $ echo $? 0
But since you're on OS X, I'm not really sure how locale information is supposed to be handled.