Environment:
Ubuntu 14.04 64-bit desktop, as guest virtual machine in virtual box
Host: MacBook Pro
在64位机器上缺省编译或运行时查找的是64位程序,但如果编译32位程序通常会遇到一些问题,这里做一个说明。
Build 32-bit C/C++ program on 64-bit Linux
sudo apt-get install g++ #to build C++ source files
sudo apt-get install g++-multilib #to build 32-bit executable on 64-bit Linux
g++ -m32 -g -o a.out file1.cpp file2.cpp #specify 32-bit binary
Run 32-bit executable on 64-bit Linux
要运行32位legacy程序,则需要安装相应的32位库文件(ia32-libs)。
首先添加 i386 architecture,然后安装必要的32位库。
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
sudo ./file-name
以下步骤可能也需要:
sudo apt-get update
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0
特别的,比如需要libgc library,则需指定i386类型下载:
sudo apt-get install libgc1c2 (for 32-bit linux)
sudo apt-get install libgc1c2:i386 (for 64-bit linux)
可以用命令 “file file_name”查看执行文件类型:
file-name: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.8, not
stripped
没有评论:
发表评论