第三周 3.10 作业 gcc -static作用?

gcc -static:
表示的是编译的时候禁止调用动态库,此时就是说完全编译出的东西是比较大的。让 gcc 进行静态编译,也就是把所有都需要的函数库都集成进编译出来的程序上,这个程序就可以不依赖外部的函数库运行了。

  1. -static 作用:
    gcc man page中,关于-static的解释如下:
    -static
    On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect.
    因为在GCC中,会优先使用shard library. 为了确保使用的是静态库,则使用此选项。
  2. 遇到的各类问题:
    问题一:
    很多第三方程序为了确保在没有相应动态库时运行正常,喜欢在编译最后应用程序时加入-static.
    在老版本Fedora中编译正常,但在新版Fedora下编译常常报错:
    cannot find -lc
    原因通常是:Fedora下,
    #yum install glibc-devel
    #yum install glibc
    #yum install gcc-c++
    都不会安装libc.a. 只安装libc.so. 所以当使用-static时,libc.so不能使用。只能报找不到libc了。
    解决方法:
    yum install glibc-static
    问题二:
    当test.c中用到math库中函数。
    gcc -o test -lm -static test.o
    此时会报错:
    test.c:(.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值