的std ::在Mac OS 10.6的语言环境破坏与LANG =的en_US.UTF-8 [英] std::locale breakage on MacOS 10.6 with LANG=en_US.UTF-8

查看:197
本文介绍了的std ::在Mac OS 10.6的语言环境破坏与LANG =的en_US.UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我移植到Ma​​cOSX的C ++应用程序(具体而言,10.6)。该应用程序大量使用C ++标准库和提升的。我最近在我有困难的理解应用观察到一些破损。

基本上,在程序运行时提高文件系统库抛出一个运行时异常。带着几分调试和谷歌搜索,我已经减少了违规调用以下最低的程序:

 的#include<区域>INT主(INT ARGC,CHAR *的argv []){
    性病::区域::全球(性病::区域设置());
    返回0;
}

当我运行这个通过g ++以及其中, LANG =的en_US.UTF-8 设置的环境中执行所产生的程序(我的电脑上是一部分这一方案失败默认的bash会话,当我创建一个新的控制台窗口)。清除环境变量( SETENV LANG = )允许程序没有问题运行。不过,我很惊讶,我看到这个破损的默认配置。

我的问题是:


  1. 是这个code此预期的行为,在Mac OS 10.6?

  2. 将一个适当的解决办法是什么?我真的不能重新写入功能,因为我们使用的是执行该语句作为内部文件系统库的一部分Boost库的版本。

为了完整起见,我要指出,从当通过打开命令启动(或从Finder),但不是当X code在调试运行的程序这个code合成崩溃程序模式。

修改按上述code对10.6.1给出的错误是:

 $ ./locale
抛出的一个实例后终止所谓的性病:: runtime_error
  什么():区域::面:: _ S_create_c_locale名无效
中止陷阱


解决方案

我最近遇到这个问题在Ubuntu 14.04 LTS和一个树莓派运行最新Raspbian喘息。

它无关,与OS X,而与G的组合++和升压(至少到V1.55),并在某些平台上的默认区域设置。有加速的bug票之类的与此相关的问题,请参阅
票#4688 并的车票#5928

我的解决方案是第一个做一些额外的环境设置,通过的这个AskUbuntu张贴

  sudo的区域根EN_US的en_US.UTF-8
须藤的dpkg-重新配置语言环境

不过,我也有,以确保环境变量 LC_ALL 设置为 LANG 的价值(最好是把这个在你的 .profile文件

 导出LC_ALL = $ LANG

在我来说,我使用的语言环境的en_US.UTF-8

最后再说一句:OP的说,当我到g运行此这个程序未能++。据我所知,这个线程是在2009年开始,但今天出现的完全没有必要在Mac 的上使用GCC和G ++好得多LLVM / Clang的编译器套件可从Apple免费,看 X $ C $ç主页。

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 in the app that I'm having difficulty understanding.

Basically, the boost filesystem library throws a runtime exception when the program runs. With a bit of debugging and googling, I've reduced the offending call to the following minimal program:

#include <locale>

int main ( int argc, char *argv [] ) {
    std::locale::global(std::locale(""));
    return 0;
}

This program fails when I run this through g++ and execute the resulting program in an environment where LANG=en_US.UTF-8 is set (which on my computer is part of the default bash session when I create a new console window). Clearing the environment variable (setenv LANG=) allows the program to run without issues. But I'm surprised I'm seeing this breakage in the default configuration.

My questions are:

  1. Is this expected behavior for this code on MacOS 10.6?
  2. What would a proper workaround be? I can't really re-write the function because the version of the boost libraries we are using executes this statement internally as part of the filesystem library.

For completeness, I should point out that the program from which this code was synthesized crashes when launched via the 'open' command (or from the Finder) but not when Xcode runs the program in Debug mode.

edit The error given by the above code on 10.6.1 is:

$ ./locale 
terminate called after throwing an instance of 'std::runtime_error'
  what():  locale::facet::_S_create_c_locale name not valid
Abort trap

解决方案

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.

这篇关于的std ::在Mac OS 10.6的语言环境破坏与LANG =的en_US.UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆