2017-06-27 129 views
0

執行make會失敗,因爲它無法在make文件中找到先前定義的規則。另外,如果我用「做目錄」中的「目錄」的規則只適用,但是當我把它添加到由規則也列出文件在工作目錄....Makefile組合規則未執行定義的其他規則

make test_tester 
dir 
base_types.c dynamic_array.c gists hashtable.c linked_list.c Makefile Makefile_OLD object.c object_table.c out.txt READ_THIS.txt sstring.c tester.c tests ttime.c 
build/test_tester.o 
make: build/test_tester.o: Command not found 
Makefile:7: recipe for target 'test_tester' failed 
make: *** [test_tester] Error 127 

CC=gcc 
CFLAGS=-Wall -I ../include 
TEST_DIR=tests 
BUILD_DIR=build 

test_tester: 
     dir 
     $(BUILD_DIR)/test_tester.o 
     $(BUILD_DIR)/tester.o 
     $(BUILD_DIR)/base_types.o 
     $(BUILD_DIR)/object.o 
     $(BUILD_DIR)/sstring.o 
     $(CC) $(CFLAGS) $(BUILD_DIR)/test_tester.o $(BUILD_DIR)/tester.o $(BUILD_DIR)/base_types.o \ 
     $(BUILD_DIR)/object.o $(BUILD_DIR)/sstring.o 

$(BUILD_DIR)/test_tester.o: 
     $(CC) $(CFLAGS) -c $(TEST_DIR)/test_tester.c -o [email protected] 

$(BUILD_DIR)/tester.o: tester.c 
     $(CC) $(CFLAGS) -c tester.c -o [email protected] 

$(BUILD_DIR)/base_types.o: base_types.c 
     $(CC) $(CFLAGS) -c base_types.c -o [email protected] 

$(BUILD_DIR)/object.o: object.c 
     $(CC) $(CFLAGS) -c object.c -o [email protected] 

$(BUILD_DIR)/sstring.o: sstring.c 
     $(CC) $(CFLAGS) -c sstring.c -o [email protected] 

dir: mkdir -p $(BUILD_DIR) 

.PHONY: clean 
clean: 
     rm -f $(BUILD_DIR)/*.o 
+1

你沒有一個組合的規則,你有'test_tester'目標沒有先決條件,只是一長串命令。 https://www.gnu.org/software/make/manual/make.html#Rule-Introduction – melpomene

+0

@melpomene規則的先決條件是否必須具有構建目錄前綴? –

+1

@eat_a_lemon先決條件與目標相同,所以你的意思是'test_tester:dir'?與dir-target相反,mkdir必須縮進到下一行 – Ctx

回答

0

我想通了感謝。

CC=gcc 
CFLAGS=-Wall -I ../include 
TEST_DIR=tests 
BUILD_DIR=build 

test_tester: dir test_tester.o tester.o base_types.o object.o sstring.o 
     $(CC) $(CFLAGS) $(BUILD_DIR)/test_tester.o $(BUILD_DIR)/tester.o $(BUILD_DIR)/base_types.o $(BUILD_DIR)/object.o $(BUILD_DIR)/sstring.o -o [email protected] 

test_tester.o: 
     $(CC) $(CFLAGS) -c $(TEST_DIR)/test_tester.c -o $(BUILD_DIR)/[email protected] 

tester.o: tester.c 
     $(CC) $(CFLAGS) -c tester.c -o $(BUILD_DIR)/[email protected] 

base_types.o: base_types.c 
     $(CC) $(CFLAGS) -c base_types.c -o $(BUILD_DIR)/[email protected] 

object.o: object.c 
     $(CC) $(CFLAGS) -c object.c -o $(BUILD_DIR)/[email protected] 

sstring.o: sstring.c 
     $(CC) $(CFLAGS) -c sstring.c -o $(BUILD_DIR)/[email protected] 

dir: 
     mkdir -p $(BUILD_DIR) 

.PHONY: clean 
clean: 
     rm -fr $(BUILD_DIR)