系统是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请问各位,这是什么原因呢?