为什么静态的main()类的程序显示错误? [英] why the program with static main() type shows error?

查看:124
本文介绍了为什么静态的main()类的程序显示错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
static int main()
{
   printf("foo");
   return 0;
}

在code给出误差

the code gives error


nfo): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

什么是错误背后的原因

what's the reason behind the error

推荐答案

在C,静态是隐藏的实施细则的主要方式。标记功能或在C变量静态意味着限制其知名度在定义它的翻译单元。从本质上讲,只有相同的C文件中的函数可以参考它们。从其他文件或库函数没有访问它们的方法。

In C, static is the primary way of "hiding" implementation details. Marking a function or a variable static in C means restricting its visibility to the translation unit in which it is defined. Essentially, only functions inside the same C file can refer to them. Functions from other files or libraries have no way of accessing them.

由于功能需要从环境的启动code(一张code说,白手起家的程序执行的)藏身访问它使你的程序非联:编译器试图找到,但它是隐藏的,因此链接器将发出错误

Since function main needs to be accessed from your environment's start-up code (a piece of code that "bootstraps" your program execution) hiding it renders your program non-linkable: compiler tries to find main, but it is hidden, so the linker issues an error.

这篇关于为什么静态的main()类的程序显示错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆