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.
- Measure the test taker's knowledge about Linux system performance indicators.
- Detailed introduction to Linux grep commands
- How to obtain the file size in Linux
- Operation notes: Linux system time viewing
- How to modify the PATH of the environment variable in Linux