Creating Your Own Executable File
Read first the previous two part of this post Part -1 & Part - 2 after reading of this two-part, then you can be understood of the following part - 3.
Note that the linker always assigns the same name a.out. When we compile another program, this file will be overwritten by the executable object code of the new program. If we want to prevent from happening, we should rename the file immediately by using the command.
mv a.out name
We may also achieve this by specifying an option in the cc command as follows:
cc -o name source-file
This will store the executable object code in the file name and prevent the old file a.out from being destroyed.
Multiple Source File
To compile and link multiple source program files, we must append all the file names to the cc command.
ccfilename - 1.cfilename-n.c
These files will be separately compiled into object files called
filename-i.o
and then linked to produce an executable program file a.out as shown in Fig. 11
Fig. 11. Compilation of multiple files |
It is also possible to compile each file separately and link them later. For example, the commands
cc -c mod1.c cc -c mod2.c
will compile the source file mod1.c and mod2.c into object files mod1.o and mod2.o. They can be linked together by the command
cc mod1.o mod2.o
we may also combine the source files and object files as follows:
cc mod1.c mod2.o
The only mod1.c is compiled and then linked with the object file mod2.o. This approach is useful when one of the multiple source files need to be changed and recompiled or an already existing object files is to be used along with the program to be compiled.
MS-DOS SYSTEM
The program can be created using any word processing software in non-document mode. The file name should end with the characters ".c" like the program.c, pay.c, etc. Then the command under the MS-DOS operating system would load the program stored in the file pay.c and generate the object code. This code has stored another file under name pay.obj. In case any language errors are found, the compilation is not completed. The program should then be corrected and compiled again.
This linking is done by the command
LINK pay.obj
which generates the executable code with the filename pay.exe. Now the command
pay
would execute the program and given the result. # allaboutprogramming62