「64bit Ubuntuで32bitアプリをコンパイルする」の編集履歴(バックアップ)一覧はこちら

64bit Ubuntuで32bitアプリをコンパイルする」(2010/10/16 (土) 19:04:05) の最新版変更点

追加された行は緑色になります。

削除された行は赤色になります。

64bit版のUbuntu10.04を使っているが、32bitでコンパイル必要があったため、32bitでコンパイルする方法を調べた。 *インストールライブラリ  32bitでコンパイルするため、利用するCライブラリなども32bit版をインストールする必要がある。 sudo apt-get install ia32-libs *コンパイル・リンク  コンパイルとリンクに「-m32」のオプションを指定すればよい。  ちなみに、64bit版OSなので、-m32をつけないと64bitでコンパイル、リンクされるが、「-m64」をつけて明示的に64bitとしてコンパイル、リンクも可能。 *サンプルソース(64bitと32bitの変数サイズの違いを表示する)  64bit版と32bit版のバイナリでは、同じ変数方でも必要とする変数のサイズが異なる。  というわけで、各変数型のサイズを表示して、確認してみる。 **ソース(size.c) #include <stdio.h> int main( int argc, char *argv[] ){ printf("char size : %d \n",(int)sizeof(char)); printf("short size : %d \n",(int)sizeof(short)); printf("int size : %d \n",(int)sizeof(int)); printf("float size : %d \n",(int)sizeof(float)); printf("long size : %d \n",(int)sizeof(long)); printf("void* size : %d \n",(int)sizeof(void*)); printf("double size : %d \n",(int)sizeof(double)); printf("long long size : %d \n",(int)sizeof(long long )); printf("long double size : %d \n",(int)sizeof(long double)); } **コンパイル -64bit gcc -m64 -o size64 size.c -32bit gcc -m32 -o size32 size.c **実行結果  まずは64bitから。 $ ./size64 char size : 1 short size : 2 int size : 4 float size : 4 long size : &color(blue){8} void* size : 8 double size : 8 long long size : 8 long double size : 16  次に32bit $ ./size32 char size : 1 short size : 2 int size : 4 float size : 4 long size : 4 void* size : 4 double size : 8 long long size : 8 long double size : 12 ---- #comment() ----
64bit版のUbuntu10.04を使っているが、32bitでコンパイル必要があったため、32bitでコンパイルする方法を調べた。 *インストールライブラリ  32bitでコンパイルするため、利用するCライブラリなども32bit版をインストールする必要がある。 sudo apt-get install ia32-libs *コンパイル・リンク  コンパイルとリンクに「-m32」のオプションを指定すればよい。  ちなみに、64bit版OSなので、-m32をつけないと64bitでコンパイル、リンクされるが、「-m64」をつけて明示的に64bitとしてコンパイル、リンクも可能。 *サンプルソース(64bitと32bitの変数サイズの違いを表示する)  64bit版と32bit版のバイナリでは、同じ変数方でも必要とする変数のサイズが異なる。  というわけで、各変数型のサイズを表示して、確認してみる。 **ソース(size.c) #include <stdio.h> int main( int argc, char *argv[] ){ printf("char size : %d \n",(int)sizeof(char)); printf("short size : %d \n",(int)sizeof(short)); printf("int size : %d \n",(int)sizeof(int)); printf("float size : %d \n",(int)sizeof(float)); printf("long size : %d \n",(int)sizeof(long)); printf("void* size : %d \n",(int)sizeof(void*)); printf("double size : %d \n",(int)sizeof(double)); printf("long long size : %d \n",(int)sizeof(long long )); printf("long double size : %d \n",(int)sizeof(long double)); } **コンパイル -64bit gcc -m64 -o size64 size.c -32bit gcc -m32 -o size32 size.c **実行結果  まずは64bitから。 $ ./size64 char size : 1 short size : 2 int size : 4 float size : 4 long size : 8 void* size : 8 double size : 8 long long size : 8 long double size : 16  次に32bit $ ./size32 char size : 1 short size : 2 int size : 4 float size : 4 long size : 4 void* size : 4 double size : 8 long long size : 8 long double size : 12 この結果を見ると、long、ポインタ、long doubleのサイズが異なることがわかる。 ---- #comment() ----

表示オプション

横に並べて表示:
変化行の前後のみ表示: