有关链接C程序的问题 [英] question about linking a c program

查看:72
本文介绍了有关链接C程序的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链接C程序

将库文件与目标程序链接的过程称为链接



1)我的问题是,链接c程序的目的是什么,为什么需要它

2)在上面定义中链接C程序的库文件是什么

Linking a C program

the process of linking library files with object program is known as linking



1) my question is that what is purpose of linking a c program why it is need

2) what is library files in above definition of linking a C program

推荐答案

在计算的糟糕年代,您的程序是从一系列源代码中汇编或编译的文件,并且必须同时编译所有文件以生成可运行的可执行文件.

那时计算机很慢,因此对于大型项目,这可能需要很长时间.我们正在谈论的是几天,而不是几分钟!因此,一些聪明的小伙子心想:如果我半编译每个文件,然后在最后将它们连接在一起,该怎么办?"因此,他做到了-将其编译为一种称为目标文件"的形式,然后编写了另一个程序以将所有目标文件一起构建-他称其为链接器.现在,只需重新编译已更改的文件即可,从而节省了整个时间!

后来,(但不久以后)将库添加到对象中,链接器可根据需要添加,以便仅在需要时才包含相关代码.
In the Bad Old Days of computing, your program was assembled or compiled from a sequence of source files, and it was necessary to compile all of them at the same time to produce a working executable.

Computers were slow then, so with big projects this could take a long time. And we are talking days, not minutes here! So some clever chap thought to himself "What if I half compile each file and then join them together at the end?" So he did - he compiled to a form known as an Object File and then wrote another program to build all the Object files together - he called this a Linker. Now, only the files that had changed needed to be compiled again, saving a whole load of time!

Later, (but not much later) Libraries were added to the objects a linker could include as necessary, so that the relevant code was only included if it was needed.


很好而且是真正的问题.

首先,让我回答您的第二个查询:
链接C程序的上述定义中的库文件是什么?
回答:库是指开发人员编写程序时需要的一组常用功能.例如,要执行字符串操作,需要strconcat,strcopy等.这些是与字符串相关的函数.所以这些都是用string.c编写的(例如),所以string.c是库文件.为了使用该库,我们必须在c程序的头文件中使用string.h.其他示例是Math.h,Stdio.h等.

我的问题是,链接c程序的目的是什么,为什么需要它
可以从此链接 [
Very good and genuine question.

First of all let me answer your second query :
what is library files in above definition of linking a C program
Ans : A library refers to the set of common functions that are needed by a developer for writing the programmes. e.g For doing string operations one needs strconcat, strcopy etc. These are string related functions. So these are written in string.c (just for example) so string.c is library file. In order to use this library we have to use string.h in the header of the c programme. Other examples are Math.h, Stdio.h etc.

my question is that what is purpose of linking a c program why it is need
The concept of linking can be better understood from this link[^]

Hope this helps.
All the best.


这篇关于有关链接C程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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