2013-11-20 46 views
4

我似乎遇到了C++语言环境的问题。当我在Eclipse中运行我的程序时,它一切正常。然而,当我尝试从从命令行运行,我不断收到此错误:当从命令行运行程序时,C++错误“failure:locale :: facet :: _ S_create_c_locale名称无效”

失败:区域::小:: _ S_create_c_locale名无效

这是触发错误代码:

// Set up UTF8 file stream 
string fileName = "./sz.txt"; 
wifstream inFileStream; 

try { 
    setlocale(LC_ALL, ""); 
    inFileStream.open(fileName.c_str()); 
    inFileStream.imbue(locale("")); 
    if(!inFileStream) { 
    return EXIT_FAILURE; 
    } 
} 
catch (const std::exception &exc) { 
    wcout << "Error while trying to create UTF8 file stream." << endl; 
    std::cerr << exc.what() << endl; 
    if(inFileStream.is_open()) 
     inFileStream.close(); 

    return EXIT_FAILURE; 
} 

的“语言环境”的输出提供了以下:

LANG="de_DE.UTF-8" 
LC_COLLATE="de_DE.UTF-8" 
LC_CTYPE="de_DE.UTF-8" 
LC_MESSAGES="de_DE.UTF-8" 
LC_MONETARY="de_DE.UTF-8" 
LC_NUMERIC="de_DE.UTF-8" 
LC_TIME="de_DE.UTF-8" 
LC_ALL="de_DE.UTF-8" 

我也试图用“de_DE.UTF-8”的语言环境字符串,而不是“”(它的方式应该是实际),但是这给了我同样的错误。

奇怪的是,在Eclipse中运行时,程序运行良好。我正在使用g ++从命令行编译以下版本:

配置为:--prefix =/Applications/Xcode.app /目录/ Developer/usr --with-gxx-include-dir =/usr /include/c++/4.2.1 苹果LLVM版本5.0(基于LLVM 3.3svn)(铛-500.2.79) 目标:x86_64的 - 苹果darwin12.4.0 线程模型:POSIX

任何想法可能这里错了吗?

干杯,

马丁

回答

4

failure: locale::facet::_S_create_c_locale name not valid

这种故障是在非GNU的平台,如果GCC没有足够好的语言环境支持典型。请参阅手册和--enable-clocale的libstdC++选项说明有:

Select a target-specific underlying locale package. The choices are 'ieee_1003.1-2001' to specify an X/Open, Standard Unix (IEEE Std. 1003.1-2001) model based on langinfo/iconv/catgets, 'gnu' to specify a model based on functionality from the GNU C library (langinfo/iconv/gettext) (from glibc, the GNU C library), 'generic' to use a generic "C" abstraction which consists of "C" locale info, 'newlib' to specify the Newlib C library model which only differs from the 'generic' model in the handling of ctype, or 'darwin' which omits the wchar_t specializations needed by the 'generic' model.

If not explicitly specified, the configure process tries to guess the most suitable package from the choices above. The default is 'generic'. On glibc-based systems of sufficient vintage (2.3 and newer), 'gnu' is automatically selected. On newlib-based systems ('--with_newlib=yes') and OpenBSD, 'newlib' is automatically selected. On Mac OS X 'darwin' is automatically selected. This option can change the library ABI.

如果你考虑到的libstdc来源++库,你会看到,除了“GNU”的模式,其他所有型号都非常存根仅支持“C”语言环境。有些平台根本没有线程安全区域设置支持。其他平台,比如达尔文(AFAIK,我没有拥有或有权访问MacOS X Darwin),确实提供了足够的线程安全的区域设置API(xlocale),应该可以在libstdC++中实现完整的C++语言环境支持。不幸的是,没有人做到这一点。

相关问题