系統是Red Hat Enterprise Linux Server release 6.5 (Santiago) i686
寫了一個簡單的helloworld程式,如下:
#include <stdio.h>
int main(void)
{
printf("Hello,World!\n");
return 0;
}
直接使用gcc靜態鏈接是正常。生成的main_static可以正常運行,如下:
$ gcc -static -fno-builtin main.c -o main_static
$ file main_static
main_static: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.18, not stripped
更換另一種步驟,先生成.o檔案,然后呼叫ld去進行鏈接,但是鏈接失敗,如下:
$ gcc -static -fno-builtin -c main.c
$ ld -static -o main main.o -L /usr/lib -lc -L /usr/lib/gcc/i686-redhat-linux/4.4.7 -lgcc -lgcc_eh
ld: warning: cannot find entry symbol _start; defaulting to 0000000008048130
/usr/lib/gcc/i686-redhat-linux/4.4.7/libgcc_eh.a(unwind-dw2.o): In function `.L107':
(.text+0xbb9): undefined reference to `__stack_chk_fail_local'
/usr/lib/gcc/i686-redhat-linux/4.4.7/libgcc_eh.a(unwind-dw2.o): In function `.L364':
(.text+0x1ac5): undefined reference to `__stack_chk_fail_local'
/usr/lib/gcc/i686-redhat-linux/4.4.7/libgcc_eh.a(unwind-dw2.o): In function `_Unwind_Backtrace':
(.text+0x24ff): undefined reference to `__stack_chk_fail_local'
/usr/lib/gcc/i686-redhat-linux/4.4.7/libgcc_eh.a(unwind-dw2.o): In function `_Unwind_ForcedUnwind':
(.text+0x26ed): undefined reference to `__stack_chk_fail_local'
/usr/lib/gcc/i686-redhat-linux/4.4.7/libgcc_eh.a(unwind-dw2.o): In function `__frame_state_for':
(.text+0x2a28): undefined reference to `__stack_chk_fail_local'
/usr/lib/gcc/i686-redhat-linux/4.4.7/libgcc_eh.a(unwind-dw2.o):(.text+0x2bb8): more undefined references to `__stack_chk_fail_local' follow
/usr/lib/gcc/i686-redhat-linux/4.4.7/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `_Unwind_Find_FDE':
(.text+0x19cb): undefined reference to `dl_iterate_phdr'
ld: main: hidden symbol `__stack_chk_fail_local' isn't defined
ld: final link failed: Nonrepresentable section on output
請問各位,這是什么原因呢?
uj5u.com熱心網友回復:
試試去掉 -lgcc_eh這是C++例外處理用的
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/77665.html
標籤:應用程序開發區
上一篇:安裝Ubuntu讓我快瘋了,請問現在這個又是出了什么問題
下一篇:ubuntu編譯工程報錯“xml.h:22: fatal error: libxml/parser.h: No such file or directory”
