cannot find -lgcc_s

  在64位centos6上编译32位的汇编程序,如果程序中使用了C库,比如printf。因为是编译32位的目标程序,所以使用gcc编译的时候需要加上-m32选项,但是如果编译的话会报错,以print.s程序为例子

 1 .code32
 2 .section .data
 3 output:
 4     .asciz "hello gas '%d'"
 5 
 6 .section .text
 7 .globl main
 8 main:
 9     pushl $4
10     pushl $output
11     call printf
12     addl $8, %esp
13 
14     pushl $0
15     call exit

  使用gcc -g -m32 -o print print.s编译的时候,会报错:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /lib/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s

  从编译错误基本可以看出来是因为没有找到gcc_s,在没有找到gcc_s之前的错误意思是系统中有gcc_s lib库,不过不匹配! 通过查询之后发现是因为64位系统使用的是64位的gcc_s库,我们目标程序是32位的,所以需要32位的gcc_s,经过一番查找之后,在http://pkgs.org/centos-6/centos-i386/libgcc-4.4.7-11.el6.i686.rpm.html目录下找到了适合版本的gcc_s 32位库,然后使用rpm安装这个包。

  然后再编译程序,使用之前的指令,程序正常运行

原文地址:https://www.cnblogs.com/chobits/p/4281732.html