2017-02-09 5 views
0

더미 C 프로젝트에 대해 다음 디렉토리 구조가 있습니다. 나의 현재 일반 메이크 파일은 다음과 같습니다일반 Makefile 빌드 디렉토리 오류

. 
├── inc 
│   ├── getmsg.c 
│   └── getmsg.h 
├── makefile 
└── src 
    └── main.c 

, 모두가 잘 컴파일이 그러나 단지 해당 .c 파일과 같은 디렉토리에 .o 인 파일을 덤프

TARGET = main 

# finds all .c files, inc/getmsg.c src/main.c 
SOURCES := $(shell find * -name *.c) 
# converts all .c files to .o files, inc/getmsg.o src/main.o 
OBJECTS := $(SOURCES:.c=.o) 
# directories that contain .h files for gcc -I flag, inc/ 
HEADERS := $(dir $(shell find * -name *.h)) 

CC  = gcc 
CFLAGS = -Wall -std=c99 -iquote "$(HEADERS)" 

all: $(TARGET) 

%.o: %.c 
    $(CC) $(CFLAGS) -c $< -o [email protected] 

$(TARGET): $(OBJECTS) 
    $(CC) -o [email protected] $^ 

clean: 
    rm -rf $(shell find * -name *.o) $(TARGET) 

.

내가하고 싶은 것은 모든 오브젝트 파일을 빌드 디렉토리에 넣는 것입니다. 이렇게하려면 파일 build/getmsg.o build/main.o을 나열하는 OBJECTSOBJECTS := $(patsubst %,build/%,$(notdir $(SOURCES:.c=.o)))으로 변경합니다. 그런 다음 %.o 대상을 build/%.o: %.c으로 설정했습니다.

그러나 이것은 No rule to make target 'build/getmsg.o'을 반환합니다. 따라서 make 파일은 .o 파일을 빌드 할 수 없습니다. 내가 여기서 무엇을 놓치고 있니?

+0

중복을 변경 http://stackoverflow.com/questions/13552575/gnu-make-pattern-to-build-output-in-different-directory -than-src –

+0

[GNU의 가능한 복제본] src와 다른 디렉토리에 출력을 빌드하는 패턴 만들기] (http://stackoverflow.com/questions/13552575/gnu-make-pattern-to-build-output-in-different- directory-than-src) –

답변

0

시도

%.o: %.c 

build/%.o: %.c 
+0

내가 싫증이 나서 "No rule"오류가 발생했습니다. – FlamingSquirrel

+0

아, 그 부분을 놓쳤습니다! 다음 링크를 확인하십시오. http://stackoverflow.com/questions/14639794/getting-make-to-create-object-files-in-a-specific-directory – MrJagaloon