Setting locales on OS X crashes

99封情书 提交于 2019-11-30 20:03:13

I don't think you're using xlocale. I believe that your problem is with libstdc++, which uses a different locale support library that is not supported on OS X, as the question EitanT links to states.

If you switch to libc++ your program will work.

The poster above it correct...the problem is with libstdc++. I wanted to add my answer because it is not straightforward how to get OS X to link against libc++ and took me over an hour to figure out.

Invoking the compiler/linker by g++ -libstd=libc++ or by clang++ -libstd=libc++ or by the alias c++ -libstd=libc++ will all fail.

The solution for compiling simple programs from the command line instead of messing with the added overhead of Xcode is to allow Xcode to handle the linking by using the command xcrun clang++ -stdlib=libc++

xcrun allows Xcode to manage the tool chain and will build a successful executable where cout.imbue(locale(foo)) will successfully work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!