author Sam Lantinga <>
Fri, 28 Nov 2014 04:51:33 -0800
changeset 9246 a761913e5e91
parent 7925 f090a47eb7f7
permissions -rwxr-xr-x
Fixed bug 2786 - "UCS-2-INTERNAL" iconv encoding is not supported everywhere, use UTF-16LE instead

Jonas Kulla

cmdline = SDL_iconv_string("UTF-8", "UCS-2-INTERNAL", (char *)(text), (SDL_wcslen(text)+1)*sizeof(WCHAR));

I'm trying to compile an SDL2 application for windows using the mingw-w64 32bit toolchain provided by my distro (Fedora 19). However, even the simplest test program that does nothing at all fails to startup with a "Fatal error - out of memory" message because the mingw iconv library provided by my distro does not support the "UCS-2-INTERNAL" encoding and the conversion returns null.

From my little bit of research, it turns out that even though this encoding is supported by the external GNU libiconv library, some glibc versions (?) don't support it with their internal iconv routines, and will instead provide the native endian encoding when "UCS-2" is specified.

Nonetheless, I wonder why the native endianness is considered in the first place when Windows doesn't even run on any big endian archs (to my knowledge). And true enough, 'WIN_StringToUTF8' from core/windows/SDL_windows.h is used everywhere else in the windows backend, which is just a macro to iconv with "UTF-16LE" as source. Therefore it would IMO make sense to use this macro here as well, which would solve my problem (patch attached).
     1 MinGW requires both the MinGW system and MSYS.
     3 There is a script for generating a series of GNU makefiles targeted
     4 at MinGW on Windows. These makefiles will build the SDL library and
     5 test executables with static links to libgcc and the same features
     6 as the Visual Studio builds. That is, they have full OpenGL support
     7 and they have no dependency on MinGW.
     9 After generating the scripts, simply navigate to the directory in
    10 a MSYS terminal and execute:
    12     make
    14 If you wish to clean the directory, you can use either the clean
    15 batch file, or call:
    17     make clean
    19 The former will remove the actual makefiles and the latter will
    20 perform a typical clean operation. You can target specific
    21 build configurations as such:
    23     make config=debug
    25 Verbosity is initially set to off. All verbosity controls is
    26 whether the resulting gcc and ar commands are printed to the
    27 console. You can enable verbose output by setting verbose to any
    28 value:
    30     make verbose=1
    32 There is currently no install target, but that is intended
    33 eventually.
    35 Ben:
    36 There is no DirectX support currently, but you can use the
    37 command option '--directx' when generating the makefiles to
    38 explicitly force the DirectX dependency on. This may have
    39 undefined behavior, so use it cautiously.