Describe the concept of Linux Makefile

Source: Internet
Author: User

Linux has become more and more popular among computer users. As a result, many users may encounter the Linux makefile problem when learning Linux. Here we will introduce the solution to the Linux makefile problem, I will share it with you here.

Write the relationship between each module into makefile and write the compilation command. In this way, when the source code of the module is modified, you can use the make command to run the makefile file to re-compile all modules involved in the module modification. Other modules do not need to worry about it.

Makefile:

Target and Component
Rules

For example, there are five files:

/* Main. c */
# Include "mytool1.h"
# Include "mytool2.h"
Int main (int argc, char ** argv)
{
Mytoolpattern print ("hello ");
Mytool2_print ("hello ");
}
/* Mytool1.h */
# Ifndef _ MYTOOL_1_H
# Define _ MYTOOL_1_H
Void mytooltypesprint (char * print_str );
# Endif
/* Mytool1.c */
# Include "mytool1.h"
Void mytooltypesprint (char * print_str)
{
Printf ("This is mytool1 print % s \ n", print_str );
}
/* Mytool2.h */
# Ifndef _ MYTOOL_2_H
# Define _ MYTOOL_2_H
Void mytool2_print (char * print_str );
# Endif
/* Mytool2.c */
# Include "mytool2.h"
Void mytool2_print (char * print_str)
{
Printf ("This is mytool2 print % s \ n", print_str );
}

You can compile it to run the executable file main.

Gcc-c main. c generate main. o)
Gcc-c mytool1.c (generate mytool1.0)
Gcc-c mytool2.c generates mytool2.0)
Gcc-o main. o mytool1.o mytool2.o (generate main)

You can also write the makefile file.

Main. o mytool. o mytool2.o
Gcc-0 $ @ $ ^
Main.0 main. c mytool1.h mytool2.h
Gcc-c $ <
Mytool1.0 mytool1.c mytool1.h
Gcc-c $ <(or mytool. c)
Mytool2.0 mytool2.c mytool2.h
Gcc-c $ <(or mytool2.c)

You can run the make command to compile the file.

There are many libraries in Linux. The various libraries written in C language are called libc. glibc is a subset of libc, which is provided by gnu, system functions and system calls provided by the kernel are not included in libc.

Glibc is installed in Linux by default.

Glibc in progress

The common library gcc will automatically find it and ignore it.

There are some standard libraries in/lib,/usr/lib,/usr/local/lib under these three paths. You only need to specify the path with the-l + Library name. Other libraries must use the specific path-L + when using gcc. This article gives you a comprehensive understanding of Linux makefile.

  1. Measure the test taker's knowledge about Linux system performance indicators.
  2. Detailed introduction to Linux grep commands
  3. How to obtain the file size in Linux
  4. Operation notes: Linux system time viewing
  5. How to modify the PATH of the environment variable in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.