如何在c ex:a.h文件中链接头文件b.c文件和main.c文件如何在c中链接它 [英] how to link header file in c ex: a.h file b.c file and main.c file how to link this in c

查看:75
本文介绍了如何在c ex:a.h文件中链接头文件b.c文件和main.c文件如何在c中链接它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何链接头文件在c

ex:啊文件bc文件和main.c文件如何在c

解决方案

<中链接blockquote> C单独编译的常用技术非常古老。它基于以下事实:声明(但不是定义)可以多次编译。基于此,人们使用基于头文件的技术。原则上,正式地说,你不必使用或者可以滥用它们,但它会使情况更糟。



所以这里头文件来了。您应该只放置声明,而不是头文件中的定义,只放置在不同C文件中的定义之间进行通信所需的声明。 头文件没有链接,它们只包含在C文件中。(是的,非常陈旧,我告诉过你,但即使使用C ++,即使使用C ++ / CLI,我们也必须使用相同的方法。)头文件被编译多次(是的,它是那么糟糕)与包含它们的C文件。



它只是保证差异编译(每个C文件是单独编译)使用相同的通用定义。这保证了我们在链接(在所有文件编译时都会发生)或在运行时期间不会出现太糟糕的惊喜,这会更糟糕。



这里有更详细的解释:

http://en.wikipedia .org / wiki / Compiler [ ^ ],

http://en.wikipedia.org/wiki/Linker_%28computing%29 [ ^ ],

http://en.wikipedia.org/wiki/Header_files [ ^ ]。



-SA

how to link header file in c
ex: a.h file b.c file and main.c file how to link this in c

解决方案

The usual technique of C separate compilation is enormously archaic. It is based on the fact that the declarations (but not the definitions) can be compiled multiple times. Based on that, people use the technique based on "header files". In principle, formally, you don''t have to use or can misuse them, but it would make the situation much worse.

So here header files come. You should put only the declarations, not definitions in header files, and only the declarations needed to communicate between definitions in different C files. Header files are not linked, they are simply included in C files. (Yes, very archaic, I told you, but even with C++, even with C++/CLI we have to use the same approach.) Header files are compiled multiple times (yes, it''s that bad) with the C files including them.

It simply guarantees that difference compilations (each C file is compiled separately) use identical common definition. That guarantees that we don''t get too bad surprises during linking (which happens when all files are compiled) or during runtime, which would be even much worse.

Everything is explained in more detail here:
http://en.wikipedia.org/wiki/Compiler[^],
http://en.wikipedia.org/wiki/Linker_%28computing%29[^],
http://en.wikipedia.org/wiki/Header_files[^].

—SA


这篇关于如何在c ex:a.h文件中链接头文件b.c文件和main.c文件如何在c中链接它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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