系统是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请问各位,这是什么原因呢?
写了一个简单的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请问各位,这是什么原因呢?
解决方案 »
- firewalld 的rule中怎么设置多个源IP段?
- 想使用qemu做虚拟机迁移的实验,想使用自己提出的在线迁移方法,应该在哪里改代码呀???原来的代码在哪里呀???
- nginx: [emerg] location "\.php/?.*" cannot be inside the exact location "/50x.ht
- shell脚本去ftp远程服务器下载文件的问题
- linux 当一个磁盘满了,如何从另外一个磁盘挪用一块空间
- 关于linux fork()的问题求大神解答
- 电脑git bash here不能用了,怎么解决啊?
- 内核
- centos7重启后挂载硬盘消失,重新挂载时提示未知文件类型无法挂载,硬盘盘有数据无法格式化!!请求帮助!!
- 很简单的Makefile 错在哪里?输出一直是Nothing to be done for `modules'
- ubuntu
- 虚拟机桥接模式没有自动获取ip
这是C++异常处理用的