Makefile writing rules and /usr/bin/ld: cannot find -lc

From the moment of learning Linux, some people have always said that whether you can write Makefile is a test of your ability to complete large-scale projects.
The makefile is related to the compilation rules of the entire project. The source files in a project are not counted, they are placed in several directories according to type, function and module. The makefile defines a series of rules to specify which files need to be compiled first, which files need to be compiled later, and which files need to be recompiled. Compilation, and even more complex functional operations, because the makefile is like a shell script, which can also execute the commands of the operating system.

The benefit of makefile is - "automatic compilation", once it is written, only one make command is needed, and the entire project is completely automatically compiled, which greatly improves the efficiency of software development. make is a command tool, a command tool that interprets the instructions in the makefile. Generally speaking, most IDEs have this command.
Compiling and linking programs

write picture description here
Let's learn about the writing of Makefile.
Suppose we need to compile a test.c file. The writing method of Makefile is as follows
. The first way to write
write picture description here

The second way of writing
write picture description here
is generally to use a static link library, just add a XXX_static to the dependent file name, and add -XXX at the end
: an error is reported when the gcc static compiler is executed:

/usr/bin/ld: cannot find -lc

collect2: ld returned 1 exit status
make: * [gcc_dry2] Error 1
(or error when calling Makefile to compile)

Reason: The program linking requires a static library, and the system does not install the static library, resulting in an error

Solution: Install static library

sudo yum install glibc-static

write picture description here
The execution of the Makefile only needs to execute a make statement to compile,
./test_static //runs in the foreground./represents the path where the system searches for executable environment variables./test_static
& //runs in the background

当需要改掉Makefile里面的依赖文件是只需在命令模式下进行替换:%s/test/main/g    //这里是指将test替换为main

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326440015&siteId=291194637