做一個跨平台的軟體,一定會遇到如何讓程式可以在32與64位元上執行。也許你會說:我的32位元執行檔可以在RHEL5 32和64上執行阿! 但在RHEL6 64bit上,預設沒安裝32位元的Libraries喔! 為了解決這個問題,你可以請使用者自己裝,也可以依據不同平台給不同的執行檔,這看各人取捨。如果想要讓執行檔可以同時在32與64上執行,可以參考下面說明。 假設我們有隻程式叫test.c,輸出執行檔為test。要compile成32與64的版本會使用以下command: # 64-bit version gcc -O2 -m64 -fPIC -Iinclude -o . / Release / test64 test.c # 32-bit version gcc -O2 -m32 -fPIC -Iinclude -o . / Release / test32 test.c 首先使用file指令去確認這兩個執行檔: file test64 # test64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), # dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped file test32 # test32: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), # dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped 接著用ldd指令去確認它們使用的dll: ldd test32 # linux-gate.so.1 => (0xffffe000) # libc.so.6 => /lib/libc.so.6 (0x00432000) # /lib/ld-linux.so.2 (0x00413000) ldd test64 # linux-vdso.so.1 => (0x00007fff48f...