sj7*_*755 25 compiler-construction optimization static gcc options
我想知道gcc上的-static选项是什么.编译某个应用程序时我需要这个选项,但是当我这样做时,我收到以下错误:
gcc -static -O3 -o prog prog.c
/usr/bin/ld: cannot find -lc
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
什么需要安装?
GCC版本:
[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)
Run Code Online (Sandbox Code Playgroud)
Ahm*_*sud 61
该-static
选项静态链接程序,换句话说,它不需要在运行时依赖动态库来运行.
要实现静态链接,需要在系统上存在库的存档(.a)版本.所以/usr/lib/libc.a /usr/lib/crt1.o等......
在现代Linux系统上(当你使用红帽时):当二进制文件链接在一起时1)要么通过.o和.a文件将代码放入可执行文件中,要么2)放入对动态库(.so)文件的引用这是由/lib/ld-linux.so(或/lib64/ld-linux=x86-64.so)解决的,它始终位于众所周知的地方.
对于您的特定系统,如果某个程序专门想要创建自己的静态版本,那么您需要安装devel工具的静态版本.您至少需要glibc-static软件包.您可能还需要libstdc ++ - 静态包.
Jon*_*ler 11
该-static
标志强制链接器仅接受静态库,而不接受任何共享库.
如果要使用-static
,则必须确保安装了静态版本的C库,这可能很难找到(大多数系统不再具有静态C库).或者你必须取消效果-static
.但是,在该示例中,这将破坏目的,-static
因为链接的唯一库是(隐式)C库.
归档时间: |
|
查看次数: |
56179 次 |
最近记录: |