-1
我似乎無法弄清楚爲什麼我的makefile沒有正確執行。我收到以下錯誤:Makefile C Linux錯誤
gcc hr_timer.c -o hr
gcc hr_timer.o -o hr_timer
gcc: error: hr_timer.o: No such file or directory
gcc: fatal error: no input files
compilation terminated.
make: *** [hr_timer] Error 4
這裏是我的makefile:
CC = gcc
CFLAGS = -pthread
all: hr_timer q2q3 process_switching thread_switching
hr_timer.o: hr_timer.c
$(CC) hr_timer.c -o hr
q2q3.o: q2q3.c
$(CC) q2q3.c -o qq
process_switching.o: process_switching.c
$(CC) process_switching.c -o pr
thread_switching.o: thread_switching.c
$(CC) thread_switching.c -o th
所有.c文件編譯就好了,而不makefile文件。謝謝!
編輯:
新的Makefile:
CC = gcc
CFLAGS = -pthread
all: hr_timer q2q3 process_switching thread_switching
hr_timer.o: hr_timer.c
$(CC) hr_timer.c -o hr hr_timer.o
q2q3.o: q2q3.c
$(CC) q2q3.c -o qq q2q3.o
process_switching.o: process_switching.c
$(CC) process_switching.c -o pr process_switching.o
thread_switching.o: thread_switching.c
$(CC) $(CFLAGS) thread_switching.c -o th thread_switching.o
錯誤:
gcc hr_timer.c -o hr hr_timer.o
gcc: error: hr_timer.o: No such file or directory
make: *** [hr_timer.o] Error 1
EDIT2(FIX):
CC = gcc
CFLAGS = -pthread
all: hr qq pr th
hr: hr_timer.c
$(CC) hr_timer.c -o hr
qq: q2q3.c
$(CC) q2q3.c -o qq
pr: process_switching.c
$(CC) process_switching.c -o pr
th: thread_switching.c
$(CC) $(CFLAGS) thread_switching.c -o th
感謝您的回覆。我提出了您提到的更改,但仍然出現錯誤。請檢查編輯。 – user5056973
它不應該是'-o hr hr_timer.o'。它應該只是'-o hr_timer.o',它表示輸出應該放入文件hr_timer.o中。中間不需要小時。仔細閱讀 –
謝謝。它現在有效。 – user5056973