基本上,你需要知道的是:
#You can make some const variables like `CC = gcc`
#and use them in the Makefile like that `$(CC)`
#(you basically wrap the variable with brackets and
#put a dollar sign before it).
CC = gcc
#The order is crutial in a makefile.
# First of all you want to compile `main` using objects
# which are yet to be linked.
main: student.o linkedlist.o
# Line below is a command
# that is already well known to you I guess: "gcc -o main ..."
$(CC) -o main student.o linkedlist.o
# If makefile doesn't have the newest version of a .o file,
# then it goes to lines below
# to find out, how can it obtain the newest version
# of student.o or linkedlist.o
# This is how it can produce the .o file:
student.o: student.c
$(CC) -c student.c
# -c flag is crutial here, because it means that you want to create
# a .o (object) file. Not an executable program.
# Same with linkedlist.c:
linkedlist.o: linkedlist.c
$(CC) -c linkedlist.c
我希望它的作品,我沒有測試它。如果我犯了任何錯誤,請糾正我。
一兩件事:請記住,你必須使用TABS而不是縮進的空格線。
此問題與您的問題類似。答案要複雜得多:https://stackoverflow.com/questions/1838040/how-exactly-do-i-use-a-makefile?rq=1 –