64位机器上的32位标准C库

时间:2012-06-17 05:32:34

标签: c shared-libraries 32bit-64bit

我在64位机器上使用ubuntu 12.04,我有这个简单的C代码:

 int b = 20;
 int c = 10;

 int main(int argc, char **argv) {
      c = 50;
 }

我试图通过编译它来与任何IA32机器兼容:

 unix> gcc -m32 code.c

并且遇到了这些错误:

 /usr/bin/ld: cannot find crt1.o: No such file or directory
 /usr/bin/ld: cannot find crti.o: No such file or directory
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a when searching for -lgcc
 /usr/bin/ld: cannot find -lgcc
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so when searching for -lgcc_s
 /usr/bin/ld: cannot find -lgcc_s
 /usr/bin/ld: cannot find -lc
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc.a when searching for -lgcc
 /usr/bin/ld: cannot find -lgcc
 /usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6/libgcc_s.so when searching for -lgcc_s
 /usr/bin/ld: cannot find -lgcc_s
 /usr/bin/ld: cannot find crtn.o: No such file or directory
 collect2: ld returned 1 exit status

据我了解,这种情况正在发生,因为我缺少32位标准C库,因此链接器无法将我的代码与标准C库链接。

如何在64位机器上获得所需的32位标准C?

1 个答案:

答案 0 :(得分:5)

试试这个:

  apt-get install ia32-libs 

此外,您应该使用-m32编译/链接:

gcc -Wall -pedantic -m32 ...