0% found this document useful (0 votes)
23 views6 pages

II. Practice 1. Create and Execute A Program

The document provides instructions and exercises on using Makefiles and basic Linux commands. It includes: - An example Makefile to recompile only changed source files. Makefiles specify dependencies to avoid unnecessary recompiling. - Questions about advantages of Makefiles, such as only recompiling changed files in large projects to save time. Examples of header and source file dependencies. - Basic Linux commands demonstrated like creating a directory and file, listing contents, viewing/showing lines of a file, and saving commands to a file. - An exercise section directs the user to perform commands like listing a directory, viewing a file, and showing lines of a file, with the results saved to the user's

Uploaded by

Hoàng Lê
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

II. Practice 1. Create and Execute A Program

The document provides instructions and exercises on using Makefiles and basic Linux commands. It includes: - An example Makefile to recompile only changed source files. Makefiles specify dependencies to avoid unnecessary recompiling. - Questions about advantages of Makefiles, such as only recompiling changed files in large projects to save time. Examples of header and source file dependencies. - Basic Linux commands demonstrated like creating a directory and file, listing contents, viewing/showing lines of a file, and saving commands to a file. - An exercise section directs the user to perform commands like listing a directory, viewing a file, and showing lines of a file, with the results saved to the user's

Uploaded by

Hoàng Lê
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

II.

Practice
1. Create and execute a program:

Error:

2. Create Makefile:
RUN:

III. Exercise:

3.1. Questions:

What are the advantages of Makefile? Give examples?

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.

Ex: INCLUDES = -I "/home/Hoangt/header"

The output will be:


+ “PARENT: value = 5”

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.

3.2. Basics commands:


Create a directory:

Create a file name example.txt:

RESULT:

1. List content of <Student ID> directory:

2. View content of example.txt:


3. Show 5 first line of example.txt:

4. Show last 5 lines of example.txt:

5. Save runned command to a file:


RESULT IN FOLDER <STUDENT ID>:

3.3. Programming Exercises:

You might also like