더미 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
을 나열하는 OBJECTS
을 OBJECTS := $(patsubst %,build/%,$(notdir $(SOURCES:.c=.o)))
으로 변경합니다. 그런 다음 %.o
대상을 build/%.o: %.c
으로 설정했습니다.
그러나 이것은 No rule to make target 'build/getmsg.o'
을 반환합니다. 따라서 make 파일은 .o 파일을 빌드 할 수 없습니다. 내가 여기서 무엇을 놓치고 있니?
중복을 변경 http://stackoverflow.com/questions/13552575/gnu-make-pattern-to-build-output-in-different-directory -than-src –
[GNU의 가능한 복제본] src와 다른 디렉토리에 출력을 빌드하는 패턴 만들기] (http://stackoverflow.com/questions/13552575/gnu-make-pattern-to-build-output-in-different- directory-than-src) –