How to use the make command in Linux ?

Linux

The make command is a powerful tool used to build and manage programs from source code on a Linux system. It is a fundamental building block of the Linux operating system, and is used to compile, link, and build programs from source code. 

Here at Fixwebnode, we shall look into how make command works.

 

What is the Make Command?

The make command is a program designed to automate the building of complex software projects. It reads instructions from a text file called a makefile, which contains instructions on how to build the project. The make command can be used to compile and link source code files, create object files, and build executable files.

 

How to Use the Make Command ?

Using the make command is simple. To use it, you first need to create a makefile, which contains instructions on how to build the project. Once the makefile has been created, you can then use the make command to build the project.

To use the make command, open a terminal window and type in the following command:

$ make -f [makefile_name]

where [makefile_name] is the name of the makefile. 

This will execute the instructions in the makefile and build the project.

 

Example of using Make Command

Let's look at an example of how to use the make command. 

Suppose we have a C program called hello.c, which contains the following code:

#include <stdio.h>
int main() {
printf("Hello World!
");
return 0;
}

To compile and link this program, we need to create a makefile, which contains instructions on how to build the project. The makefile should look like this:

hello: hello.c
gcc -o hello hello.c

This makefile contains instructions on how to build the hello program. It tells the make command to use the GNU C Compiler (gcc) to compile and link the hello.c source file and create an executable file called hello.

 

Now that we have created the makefile, we can use the make command to build the project. To do this, open a terminal window and type in the following command:

$ make -f hello

This will execute the instructions in the makefile and build the hello program. Once it is finished, you should have an executable file called hello in the current directory.

 

[Need Linux Support ? We can help you. ]

 


Conclusion

Your Cart