凡在C标准库中的函数定义的? [英] Where are the functions in the C standard library defined?

查看:139
本文介绍了凡在C标准库中的函数定义的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不感兴趣源$ C ​​$ C,我想知道如何在C编译器(GCC)实际上发现的功能。如,当preprocessor看到,我已经包括 stdio.h中,它在哪里去找找定义函数体中的文件?

I'm not interested in the source code, I want to know how the C compiler (GCC) actually finds the functions. As in, when the preprocessor sees that I've included stdio.h, where does it look to find the files that define the function bodies?

修改

我可能也说我使用Ubuntu 12.04,但如果有一个笼统的回答,那工作了。

I should probably also say I'm using Ubuntu 12.04, but if there's a general answer, that would work too.

推荐答案

GCC 自带(二进制)目标文件(的的C源文件)包含的所有标准C函数实现。当您使用 GCC 来目标文件链接成一个可执行文件,链接器的自动的包括实现标准库函数的目标文件。根据这个线程,该标准的目标文件可能会叫做的libc.a libc.so

gcc comes with (binary) object files (not C source files) which contain implementations of all the standard C functions. When you use gcc to link object files into an executable file, the linker automatically includes the object files which implement the standard library functions. According to this thread, that standard object file will probably be called libc.a or libc.so.

假设你在程序中包含的printf 到的电话。当链接器将尝试解决,其中该呼叫应该去,它会找到的printf的的libc.a 的定义,使您的函数调用有道理。

Say you include a call to printf in your program. When the linker tries to resolve where that call should go, it will find the definition of printf in libc.a, and make your function call point there.

看<一个href=\"http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html\">http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html并注意 -nostdlib -nodefaultlibs 选项。您可以使用这些选项来告诉 GCC 的连接器的导入默认包含的标准库的目标文件。

Look at http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html and note the -nostdlib and -nodefaultlibs options. You can use these options to tell gcc's linker not to include the standard library object files by default.

这篇关于凡在C标准库中的函数定义的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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