-static选项gcc? [英] -static option for gcc?
问题描述
我想知道gcc上的-static选项。我需要这个选项,当编译某个应用程序时,但是当我这样做,我得到以下错误:
gcc -static -O3 - o prog prog.c
/ usr / bin / ld:找不到-lc
collect2:ld返回1退出状态
需要安装什么?
GCC版本:
[user @ localhost dir] $ gcc -v
pre>
使用内置规格。
COLLECT_GCC = gcc
COLLECT_LTO_WRAPPER = / usr / libexec / gcc / x86_64-redhat-linux / 4.6.1 / lto-wrapper
目标:x86_64-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-linker-build-id --enable-languages = c,c ++,objc,obj-c ++,java,fortran,ada,go,lto --enable-plugin --enable-java-awt = 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_32 = i686 - build = x86_64-redhat-linux
线程模型:posix
gcc版本4.6.1 20110908(Red Hat 4.6.1-9)(GCC)
解决方案你通常应该避免静态链接你的应用程序(你应该解释我们为什么不希望通常的动态链接) 。我建议至少动态链接系统库(
libc
值得注意) - 如果你绝对需要,你可以链接较少的公共库静态。为什么要静态链接您的应用程序?它通常是一个错误(因为你不会从系统动态库的更新中获利)。特别是libc
的名称服务切换设施需要动态库。
您的系统应该已经安装了提供静态libc库的包。在Debian上,它是
libc-dev
包,但我不知道它是在RedHat上。
要找出
gcc
的作用,请传递-v
标志,例如gcc -v -static -O3 -o prog prog.c
b $ b但是你不应该静态链接你的程序。在我的Debian发行版中,
/ usr / bin
中有超过700个程序,只有一个是静态链接的。I'm wondering what the -static option on gcc does. I need this option when compiling a certain application, however when I do I get the following error:
gcc -static -O3 -o prog prog.c /usr/bin/ld: cannot find -lc collect2: ld returned 1 exit status
What needs installation?
GCC version:
[user@localhost dir]$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.6.1/lto-wrapper Target: x86_64-redhat-linux Configured with: ../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-linker-build-id --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --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_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.6.1 20110908 (Red Hat 4.6.1-9) (GCC)
解决方案You generally should avoid statically linking your application (and you should explain us why you don't want usual dynamic linking). I suggest at least to link dynamically the system libraries (
libc
notably) - if you absolutely want, you could link less common libraries statically - . Why do you want to link statically your application? It is generally a mistake (because you don't profit from updates to the system dynamic libraries). In particular name service switch facilities fromlibc
wants dynamic libraries.Your system should have installed the package providing the static libc library. On Debian, it is the
libc-dev
package but I don't know what it is on RedHat.To find out what
gcc
does, pass it the-v
flag likegcc -v -static -O3 -o prog prog.c
But you should not link statically your programs. On my Debian distributions, there are more than 700 programs in
/usr/bin
and only one is statically linked.这篇关于-static选项gcc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!