make file compiles但不运行

时间:2016-05-07 03:04:17

标签: gcc makefile

# Macros
CC = gcc
COMP_FLAG = -std=c99 -Wall -pedantic-errors -Werror -DNDEBUG
LIB_FLAG = -L. -lmtm -lex1
# Main target
tests: yad3_test realtor_test customer_test

# Targets make <file>

yad3_test: yad3_test.o yad3.o realtor.o customer.o
    $(CC) yad3_test.o yad3.o realtor.o customer.o $(LIB_FLAG) -o $@
yad3_test.o: tests/yad3_test.c yad3.h customer.h realtor.h apartment_service.h apartment.h tests/test_utilities.h mtm_ex2.h
    $(CC) -c $(COMP_FLAG) $(LIB_FLAG) tests/$*.c
yad3.o:  yad3.c yad3.h customer.h realtor.h apartment_service.h apartment.h mtm_ex2.h list.h map.h
    $(CC) -c $(COMP_FLAG) $(LIB_FLAG) $*.c
realtor.o: realtor.c realtor.h apartment_service.h apartment.h map.h
    $(CC) -c $(COMP_FLAG) $(LIB_FLAG) $*.c
customer.o: customer.c map.h customer.h
    $(CC) -c $(COMP_FLAG) $(LIB_FLAG) $*.c


realtor_test: realtor_test.o realtor.o
    $(CC) realtor_test.o realtor.o $(LIB_FLAG) -o $@
realtor_test.o: tests/realtor_test.c realtor.h apartment_service.h apartment.h tests/test_utilities.h
    $(CC) -c $(COMP_FLAG) $(LIB_FLAG) tests/$*.c
#realtor.o: realtor.c realtor.h apartment_service.h apartment.h map.h
#   $(CC) -c $(COMP_FLAG) $(LIB_FLAG) $*.c


customer_test: customer_test.o customer.o
    $(CC) customer_test.o customer.o $(LIB_FLAG) -o $@
customer_test.o: tests/customer_test.c customer.h tests/test_utilities.h
    $(CC) -c $(COMP_FLAG) $(LIB_FLAG) tests/$*.c
#customer.o: customer.c map.h customer.h
#   $(CC) -c $(COMP_FLAG) $(LIB_FLAG) $*.c



run: run_yad3_test run_realtor_test run_customer_test

run_clean: clean run

#run_my_set_test: my_set_test
#   ./my_set_test

run_yad3_test: yad3_test
    ./yad3_test

realtor_test_test: realtor_test
    ./realtor_test

run_customer_test: customer_test
    ./customer_test

# Target remove all <*_test> and <*.o> files
clean: clean_o clean_test

clean_test:
    rm -f *_test
clean_o:
    rm -f *.o

编译是否正常工作是否有任何合理的原因,但它没有正确运行最终创建的测试???

似乎写得正确并且没有任何理由。它不应该工作。帮助任何人?

1 个答案:

答案 0 :(得分:1)

默认情况下make运行该文件的第一个目标,因此您只需将run规则移到顶部,makemake run移动。{/ p>

此外,由于GNU Make 3.81 .DEFAULT_GOAL允许覆盖此行为,因此,如果您愿意,请保留实际订单,请添加:

.DEFAULT_GOAL = run