II. Practice 1. Create and Execute A Program
II. Practice 1. Create and Execute A Program
Practice
1. Create and execute a program:
Error:
2. Create Makefile:
RUN:
III. Exercise:
3.1. Questions:
A makefile is useful because (if properly defined) allows recompiling only what is
needed when you make a change. In a large project rebuilding the program can take some
serious time because there will be many files to be compiled and linked and there will be
documentation, tests, exampleS.
It makes codes more concise and clear to read and debug. No need to compile the
entire program every time whenever you make a change to the functionality or a class.
Makefile will automatically compile only those files where change has occurred.
Examples: When a C/C++ source file is changed, it must be recompiled. If a header file has
changed, each C/C++ source file that includes the header file must be recompiled to be safe.
Each compilation produces an object file corresponding to the 9 source file. Finally, if any
source file has been recompiled, all the object files, whether newly made or saved from
previous compilations, must be linked together to produce the new executable program.
These instructions with their dependencies are specified in a makefile. If none of the files that
are prerequisites have been changed since the last time the program was compiled, no
actions take place.
Examples we have 4 sources code files: main.c, b.c. ab.c and d.c which order is
a.h->b.c->c.h->d.c. We use a trivial way to compiled and executes: gcc main.cpp b.c ab.c d.c.
If we have thousands of source codes, it is hard to do that. But makefile can make it easily.
In case of source code files located in different places, how can we write a Makefile?
It is required to provide the path of header files. This can be done using -I option in
makefile.
Because global variable changes does not affect others because data/state of 2
processes is different. Also, parent and child run simultaneously so we have that output.
RESULT: