Home > OS >  GCC static link failure
GCC static link failure

Time:09-25

System is a Red Hat Enterprise Linux Server release 6.5 (Santiago) i686
Write a simple helloworld program, as follows:
# include & lt; Stdio. H>
Int main (void)
{
Printf (" Hello, World! \n");
return 0;
}

Directly using GCC static link is normal, the generated main_static can run normally, as follows:
$GCC - static - fno - builtin main. C - o main_static
$file main_static
Main_static: ELF 32 - bit LSB executable that Intel 80386, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.18, not stripped

Change another step, Mr. O file, then calls the ld to link, link failure, however, is as follows:
$GCC - static - fno - builtin - the main c. 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: always find entry symbol _start; Defaulting to 0000000008048130
The/usr/lib/GCC/i686 - redhat Linux/4.4.7/libgcc_eh (unwind - dw2. O) : a function In `. L107 ':
(. Text + 0 xbb9) : undefined reference to ` __stack_chk_fail_local '
The/usr/lib/GCC/i686 - redhat Linux/4.4.7/libgcc_eh (unwind - dw2. O) : a function In `. L364 ':
(. Text + 0 x1ac5) : undefined reference to ` __stack_chk_fail_local '
The/usr/lib/GCC/i686 - redhat Linux/4.4.7/libgcc_eh (unwind - dw2. O) : a function In ` _Unwind_Backtrace ':
(. Text + 0 x24ff) : undefined reference to ` __stack_chk_fail_local '
The/usr/lib/GCC/i686 - redhat Linux/4.4.7/libgcc_eh (unwind - dw2. O) : a function In ` _Unwind_ForcedUnwind ':
(. Text + 0 x26ed) : undefined reference to ` __stack_chk_fail_local '
The/usr/lib/GCC/i686 - redhat Linux/4.4.7/libgcc_eh (unwind - dw2. O) : a function In ` __frame_state_for ':
(. Text + 0 x2a28) : undefined reference to ` __stack_chk_fail_local '
/usr/lib/GCC/i686 - redhat Linux/4.4.7/libgcc_eh (unwind - dw2. O) : (. "text + 0 x2bb8) : more undefined references to ` __stack_chk_fail_local 'follow
The/usr/lib/GCC/i686 - redhat Linux/4.4.7/libgcc_eh a (unwind - dw2 - fde - glibc. O) : In the function ` _Unwind_Find_FDE ':
(. Text + 0 x19cb) : undefined reference to ` dl_iterate_phdr '
Ld: main: hidden symbol ` __stack_chk_fail_local 'isn' t defined
Ld: final link failed: Nonrepresentable section on the output

Excuse me, ladies and gentlemen, what reason is this?

CodePudding user response:

Try to get rid of - lgcc_eh
This is for the use of c + + exception handling
  • Related