我試圖從當前文件夾使用um.c 編譯一個名爲um的程序,幷包含一些外部實現。 .h文件位於一個目錄中,但實現這些.h文件的.c文件位於不同的目錄中。以下是我的makefile。看起來編譯器知道在哪裏查找.h文件。但是,鏈接失敗,併產生錯誤:使用makefile從不同目錄鏈接.h文件和.c文件
ld: symbol(s) not found for architecture x86_64
clang: fatal error: linker command failed with exit code 1
的Makefile:
# define the C compiler to use
CC = gcc
# define any compile-time flags
CFLAGS = -g -O -Wall -Wextra -Werror -Wfatal-errors -std=c99 -pedantic
# define any directories containing header files other than /usr/include
INCLUDES = -I/Users/nguyenmanhduc/Documents/C\ library/cii/include
# define library paths in addition to /usr/lib
LFLAGS = -L/Users/nguyenmanhduc/Documents/C\ library/cii/src
# define any libraries to link into executable:
LIBS = -lm
# define the C source files
SRCS = um.c
# define the C object files
OBJS = $(SRCS:.c=.o)
# define the executable file
MAIN = um
.PHONY: depend clean
all: $(MAIN)
@echo Simple compiler named um has been compiled
$(MAIN): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o [email protected]
clean:
$(RM) *.o *~ $(MAIN)
depend: $(SRCS)
makedepend $(INCLUDES) $^
這個問題看似奇怪,因爲我有一個makefile文件沒有什麼經驗,但沒有辦法,我可以鏈接.H的方式和.c文件使用makefile在不同的文件夾中。
謝謝!