【发布时间】:2016-10-30 02:52:40
【问题描述】:
我似乎无法弄清楚为什么我的 makefile 没有正确执行。我收到以下错误:
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
这是我的生成文件:
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 的情况下正常编译。谢谢!
编辑:
新的生成文件:
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(修复):
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
【问题讨论】: