せっかくなのでUnicode版も
せっかくtchar.h
を使って書いたのでUnicode版も作る。
当然ソースはそのままでUnicode版にする旨をコンパイラに指示する。
$ i686-w64-mingw32-gcc -Wall -ansi -pedantic -o hello.exe hello.c -mwindows -municode -D_UNICODE
UNICODE
と_UNICODE
を定義してもMinGW-w64はエラーを吐く。
さらにオプション-municode
を指定することでUnicode版ができる。
$ i686-w64-mingw32-gcc -v --help 2> /dev/null | grep -- -municode -municode Use unicode startup and define UNICODE macro
とのことなので、-DUNICODE
は無くてもUNICODE
が定義される。
$ file hello.exe hello.exe: PE32 executable (GUI) Intel 80386, for MS Windows $ objdump -p hello.exe | grep "DLL N" DLL Name: KERNEL32.dll DLL Name: msvcrt.dll DLL Name: USER32.dll $ objdump -p hello.exe | grep MessageBox 64da 443 MessageBoxW
きちんとMessageBoxW
にリンクされている。
ちなみに前回作成したMBCS版だと、
$ objdump -p hello.exe | grep MessageBox 64d6 438 MessageBoxA
MessageBoxA
にリンクされていることが分かる。