kangear 发表于 2013-01-10 13:02

不能静态编译是怎么回事:

# gcc hello.c -static
/usr/bin/ld: cannot find -lc
collect2: ld 返回 1
#

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

这个问题该怎么解决呢?

我的是RHEL6.3。

kangear 发表于 2013-01-10 13:06

我把这个错误也google了一大圈,不过他们遇到的都是动态编译的问题,没有办法和他们一样,我该怎么办呢?

kangear 发表于 2013-01-10 13:16

静态编译过程:# gcc hello.c -static -v
使用内建 specs。                           
目标:i686-redhat-linux                     
配置为:../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            
线程模型:posix                                                                                                                           
gcc 版本 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC)                                                                                          
COLLECT_GCC_OPTIONS='-static' '-v' '-mtune=generic' '-march=i686'                                                                        
/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                                                                                                                        
忽略不存在的目录“/usr/lib/gcc/i686-redhat-linux/4.4.6/include-fixed”                                                                     
忽略不存在的目录“/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../i686-redhat-linux/include”                                             
#include "..." 搜索从这里开始:                                                                                                            
#include <...> 搜索从这里开始:                                                                                                            
/usr/local/include                                                                                                                        
/usr/lib/gcc/i686-redhat-linux/4.4.6/include                                                                                             
/usr/include                                                                                                                              
搜索列表结束。                                                                                                                           
GNU C (GCC) 版本 4.4.6 20120305 (Red Hat 4.4.6-4) (i686-redhat-linux)                                                                     
      由 GNU C 版本 4.4.6 20120305 (Red Hat 4.4.6-4) 编译,GMP 版本 4.3.1,MPFR 版本 2.4.1。                                             
GGC 准则:--param ggc-min-expand=98 --param ggc-min-heapsize=128840                                                                        
Compiler executable checksum: 506e10f785e7685b65c06e4e4f09a704                                                                           
COLLECT_GCC_OPTIONS='-static' '-v' '-mtune=generic' '-march=i686'                                                                        
as -V -Qy -o /tmp/ccOkF991.o /tmp/ccgvUlfr.s                                                                                             
GNU assembler version 2.20.51.0.2 (i686-redhat-linux) using BFD version version 2.20.51.0.2-5.34.el6 20100205                              
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/
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/
COLLECT_GCC_OPTIONS='-static' '-v' '-mtune=generic' '-march=i686'
/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
/usr/bin/ld: cannot find -lc
collect2: ld 返回 1
#

kangear 发表于 2013-01-10 13:17

hello.c#include<stdio.h>
int main()
{
printf("Hello World!\n");
}

kangear 发表于 2013-01-10 13:35

解决了,我在RHEL5上是可以静态链接的,就锁定的是缺少libc.a,就在RHEL5上 locate 一下,找到了,就拷贝过来 ,就好了。

MMMIX 发表于 2013-01-10 17:21

kangear 发表于 2013-01-10 13:35 static/image/common/back.gif
解决了,我在RHEL5上是可以静态链接的,就锁定的是缺少libc.a,就在RHEL5上 locate 一下,找到了,就拷贝过 ...

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

kangear 发表于 2013-01-10 19:46

好像没有这个包呀?
这是光盘中的:
页: [1]
查看完整版本: 不能静态编译是怎么回事: