Linux with Operating System Concepts



Download 5,65 Mb.
Pdf ko'rish
bet207/254
Sana22.07.2022
Hajmi5,65 Mb.
#840170
1   ...   203   204   205   206   207   208   209   210   ...   254
Bog'liq
Linux-with-Operating-System-Concepts-Fox-Richard-CRC-Press-2014

headername
.h>
or 
#include “
headername
.h”
depending on whether the header 
file is part of the C/C
++
library or one of your own header files, respectively.
If you are utilizing library file functions, then another step in the compilation process must 
take place. This is known as linking. Linking can take place either during compilation, in 
which case it is known as static linking, or at run-time, in which case it is known as dynamic 
linking. Linking takes already-compiled functions and loads them into your program.
If linking is done statically, then your program will be completed during the compila-
tion process. This means that the program, when executed, is not slowed by the necessity 
of run-time linking or loading. It also means that your program can be completely opti-
mized at compile time. However, if your compiler performs static linking, it means that the 
executable program will contain 
all
functions called in your program.
Consider the following C statement:
if (x 
<
0) {
foo1();
foo2();
}
If at run-time x is not less than 0, then these two functions are not called. If in fact these 
functions are only called from this code and nowhere else in the program and if x is not 
expected to be less than 0, then static linking will increase your program’s size somewhat 
unnecessarily.
Instead, with dynamic linking, library functions are only linked to and loaded on 
demand (as needed). While this may slow down the processing of the program as it has to 
wait to load additional content at run-time, it makes up for the problem above where func-
tions may not be necessary. On the other hand, reliance on run-time linking and loading 
can also lead to run-time errors if the needed libraries are not available on the system. This 
problem may only be discovered at run-time rather than compile time if you are using 
dynamic linking.
In C/C
++
, functions default to being dynamically linked but this can be overridden 
by using the reserved word 
static
. When compiling your program, to specify statically 


Software Installation and Maintenance

557
linked files, use the .a extension while dynamically linked files use the .o extension. As 
noted here, linking is a separate compilation step. In the next subsection, we examine 
gcc specifically and see that we can include linking with compilation or perform linking 
separately.
13.6.5 Using gcc
The gcc command can range from simple to convoluted depending upon the operations that 
the user wishes to perform. At its simplest, you specify 
gcc
[compilation-option]
filename
.
The compilation option will be one of –c, -S, or –E, where –c performs compilation or 
assembly but no linking, -S performs compilation but not assembly, or –E stops after the 
preprocessing stage. If no compilation option is given, then compilation performs prepro-
cessing, compilation, linking, and assembly combined.
By using –c, the output produced by the compiler is an object file (with a .o extension). 
You would use –c to create a library file that other programs might link to. By itself, the 
.o file is not executable but can only be used by the compiler to produce other compiled 
programs.
If not specified in the gcc command, the resulting executable file will be stored as 
a.out
in the current directory. To alter the output file name, add the option 
–o
filename
. Thus, 
gcc foo.c
will produce 
a.out
while 
gcc foo.c –o foo
will produce the executable 
file 
foo
.
There are a number of different options available to specify the type of language that 
gcc is to compile. These include 
-ansi
for ansi standard C, 
-std=

Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   203   204   205   206   207   208   209   210   ...   254




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish