免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4211 | 回复: 6
打印 上一主题 下一主题

[Linux] 不能静态编译是怎么回事: [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-01-10 13:02 |只看该作者 |倒序浏览
[root@localhost gcc]# gcc hello.c -static
/usr/bin/ld: cannot find -lc
collect2: ld 返回 1
[root@localhost gcc]#

就是一个简单的helloworld程序,动态编译是可以的。。。。

这个问题该怎么解决呢?

我的是RHEL6.3。

论坛徽章:
0
2 [报告]
发表于 2013-01-10 13:06 |只看该作者
我把这个错误也google了一大圈,不过他们遇到的都是动态编译的问题,没有办法和他们一样,我该怎么办呢?

论坛徽章:
0
3 [报告]
发表于 2013-01-10 13:16 |只看该作者
静态编译过程:
  1. [root@localhost gcc]# gcc hello.c -static -v
  2. 使用内建 specs。                           
  3. 目标:i686-redhat-linux                     
  4. 配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch=i686 --build=i686-redhat-linux            
  5. 线程模型:posix                                                                                                                           
  6. gcc 版本 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC)                                                                                            
  7. COLLECT_GCC_OPTIONS='-static' '-v' '-mtune=generic' '-march=i686'                                                                          
  8. /usr/libexec/gcc/i686-redhat-linux/4.4.6/cc1 -quiet -v hello.c -quiet -dumpbase hello.c -mtune=generic -march=i686 -auxbase hello -version -o /tmp/ccgvUlfr.s                                                                                                                        
  9. 忽略不存在的目录“/usr/lib/gcc/i686-redhat-linux/4.4.6/include-fixed”                                                                       
  10. 忽略不存在的目录“/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../i686-redhat-linux/include”                                               
  11. #include "..." 搜索从这里开始:                                                                                                            
  12. #include <...> 搜索从这里开始:                                                                                                            
  13. /usr/local/include                                                                                                                        
  14. /usr/lib/gcc/i686-redhat-linux/4.4.6/include                                                                                             
  15. /usr/include                                                                                                                              
  16. 搜索列表结束。                                                                                                                             
  17. GNU C (GCC) 版本 4.4.6 20120305 (Red Hat 4.4.6-4) (i686-redhat-linux)                                                                     
  18.         由 GNU C 版本 4.4.6 20120305 (Red Hat 4.4.6-4) 编译,GMP 版本 4.3.1,MPFR 版本 2.4.1。                                             
  19. GGC 准则:--param ggc-min-expand=98 --param ggc-min-heapsize=128840                                                                        
  20. Compiler executable checksum: 506e10f785e7685b65c06e4e4f09a704                                                                             
  21. COLLECT_GCC_OPTIONS='-static' '-v' '-mtune=generic' '-march=i686'                                                                          
  22. as -V -Qy -o /tmp/ccOkF991.o /tmp/ccgvUlfr.s                                                                                             
  23. GNU assembler version 2.20.51.0.2 (i686-redhat-linux) using BFD version version 2.20.51.0.2-5.34.el6 20100205                              
  24. COMPILER_PATH=/usr/libexec/gcc/i686-redhat-linux/4.4.6/:/usr/libexec/gcc/i686-redhat-linux/4.4.6/:/usr/libexec/gcc/i686-redhat-linux/:/usr/lib/gcc/i686-redhat-linux/4.4.6/:/usr/lib/gcc/i686-redhat-linux/:/usr/libexec/gcc/i686-redhat-linux/4.4.6/:/usr/libexec/gcc/i686-redhat-linux/:/usr/lib/gcc/i686-redhat-linux/4.4.6/:/usr/lib/gcc/i686-redhat-linux/
  25. LIBRARY_PATH=/usr/lib/gcc/i686-redhat-linux/4.4.6/:/usr/lib/gcc/i686-redhat-linux/4.4.6/:/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../:/lib/:/usr/lib/
  26. COLLECT_GCC_OPTIONS='-static' '-v' '-mtune=generic' '-march=i686'
  27. /usr/libexec/gcc/i686-redhat-linux/4.4.6/collect2 --build-id -m elf_i386 --hash-style=gnu -static /usr/lib/gcc/i686-redhat-linux/4.4.6/../../../crt1.o /usr/lib/gcc/i686-redhat-linux/4.4.6/../../../crti.o /usr/lib/gcc/i686-redhat-linux/4.4.6/crtbeginT.o -L/usr/lib/gcc/i686-redhat-linux/4.4.6 -L/usr/lib/gcc/i686-redhat-linux/4.4.6 -L/usr/lib/gcc/i686-redhat-linux/4.4.6/../../.. /tmp/ccOkF991.o --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/i686-redhat-linux/4.4.6/crtend.o /usr/lib/gcc/i686-redhat-linux/4.4.6/../../../crtn.o
  28. /usr/bin/ld: cannot find -lc
  29. collect2: ld 返回 1
  30. [root@localhost gcc]#
复制代码

论坛徽章:
0
4 [报告]
发表于 2013-01-10 13:17 |只看该作者
hello.c
  1. #include<stdio.h>
  2. int main()
  3. {
  4.   printf("Hello World!\n");
  5. }
复制代码

论坛徽章:
0
5 [报告]
发表于 2013-01-10 13:35 |只看该作者
解决了,我在RHEL5上是可以静态链接的,就锁定的是缺少libc.a,就在RHEL5上 locate 一下,找到了,就拷贝过来 ,就好了。

论坛徽章:
95
程序设计版块每日发帖之星
日期:2015-09-05 06:20:00程序设计版块每日发帖之星
日期:2015-09-17 06:20:00程序设计版块每日发帖之星
日期:2015-09-18 06:20:002015亚冠之阿尔艾因
日期:2015-09-18 10:35:08月度论坛发贴之星
日期:2015-09-30 22:25:002015亚冠之阿尔沙巴布
日期:2015-10-03 08:57:39程序设计版块每日发帖之星
日期:2015-10-05 06:20:00每日论坛发贴之星
日期:2015-10-05 06:20:002015年亚冠纪念徽章
日期:2015-10-06 10:06:482015亚冠之塔什干棉农
日期:2015-10-19 19:43:35程序设计版块每日发帖之星
日期:2015-10-21 06:20:00每日论坛发贴之星
日期:2015-09-14 06:20:00
6 [报告]
发表于 2013-01-10 17:21 |只看该作者
kangear 发表于 2013-01-10 13:35
解决了,我在RHEL5上是可以静态链接的,就锁定的是缺少libc.a,就在RHEL5上 locate 一下,找到了,就拷贝过 ...


你应该在 RHEL6.3 上把 glibc-static 安装上

论坛徽章:
0
7 [报告]
发表于 2013-01-10 19:46 |只看该作者
好像没有这个包呀?
这是光盘中的:
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP