とりあえず記録
libiconv - GNU Project - Free Software Foundation (FSF)
環境
- でびあん
- GCC 4.3.2 っぽい
ダウンロード
インストール
- $ ./configure --prefix=/usr/local
- $ make
- $ make install
とりあえずやった
- $ export LD_PRELOAD=/usr/local/lib/preloadable_libiconv.so
libiconv.so.2 が見つかんないとかいいよるので
# vi /etc/ld.so.conf
/usr/local/lib ← 追加# ldconfig ← 実行
Apache2.2のコンパイルでapxsエラー(libiconv.so.2エラー)解消方法 - Develog - Webアプリケーション、インフラに関する記録
- gcc -L:/usr/local/lib/ -l:libiconv.so iconv_test.c
結果
$ ./a.out
success
あいうえおかきくけこさしすせそたちつてと
success
�����������������������������������Ă
ソース
#include <stdio.h> #include <iconv.h> #define MAX_BUF 1024 int main (int argc, char **argv) { // sjis の"あいうえおかきくけこさしすせそたちつてと" const char sjis[] = { 0x82,0xA0,0x82,0xA2,0x82,0xA4,0x82,0xA6,0x82,0xA8, 0x82,0xA9,0x82,0xAB,0x82,0xAD,0x82,0xAF,0x82,0xB1, 0x82,0xB3,0x82,0xB5,0x82,0xB7,0x82,0xB9,0x82,0xBB, 0x82,0xBD,0x82,0xBF,0x82,0xC2,0x82,0xC4,0x82,0xC6, 0x00 }; // utf8 の"あいうえおかきくけこさしすせそたちつてと" const char utf8[] = { 0xE3,0x81,0x82,0xE3,0x81,0x84,0xE3,0x81,0x86,0xE3, 0x81,0x88,0xE3,0x81,0x8A,0xE3,0x81,0x8B,0xE3,0x81, 0x8D,0xE3,0x81,0x8F,0xE3,0x81,0x91,0xE3,0x81,0x93, 0xE3,0x81,0x95,0xE3,0x81,0x97,0xE3,0x81,0x99,0xE3, 0x81,0x9B,0xE3,0x81,0x9D,0xE3,0x81,0x9F,0xE3,0x81, 0xA1,0xE3,0x81,0xA4,0xE3,0x81,0xA6,0xE3,0x81,0xA8, 0x00 }; { char inbuf[MAX_BUF+1] = { 0 }; char outbuf[MAX_BUF+1] = { 0 }; char *in = inbuf; char *out = outbuf; size_t in_size = (size_t)MAX_BUF; size_t out_size = (size_t)MAX_BUF; iconv_t ic = iconv_open("UTF-8", "SJIS"); memcpy( in, sjis, sizeof(sjis) ); iconv( ic, &in, &in_size, &out, &out_size ); iconv_close(ic); int ret = memcmp( outbuf, utf8, sizeof(utf8) ); printf(ret == 0 ? "success\n" : "failed\n" ); printf("%s\n", outbuf ); } { char inbuf[MAX_BUF+1] = { 0 }; char outbuf[MAX_BUF+1] = { 0 }; char *in = inbuf; char *out = outbuf; size_t in_size = (size_t)MAX_BUF; size_t out_size = (size_t)MAX_BUF; iconv_t ic = iconv_open("SJIS", "UTF-8"); memcpy( in, utf8, sizeof(utf8) ); iconv( ic, &in, &in_size, &out, &out_size ); iconv_close(ic); int ret = memcmp( outbuf, sjis, sizeof(sjis) ); printf(ret == 0 ? "success\n" : "failed\n" ); printf("%s\n", outbuf ); } return 0; }