[英]I need some assistance with Makefile in my project
I'm trying to make a Makefile but I'm having some problems 我正在尝试制作Makefile,但遇到了一些问题
first I have 首先我有
2 source files: ~/main.c ~/lib/library.c 1 header file: ~/include/library.h 2个源文件:〜/ main.c〜/ lib / library.c 1个头文件:〜/ include / library.h
main.c and library.c both share the same header file library.h main.c和library.c都共享相同的头文件library.h
# Compiler options
CC = gcc
INC = -I../include
CFLAGS = -Wall -g -c $(INC)
LIB = -L../lib
LFLAGS = -Wall -g $(LIB)
# Dependencies
LIBS = -libmylib
OBJS = main.o
SRCS = $(OBJS:.o=.c)
EXEC = a.out
# Other rules
RM = rm -rf
TAGS = tags
BAK = Makefile.bak
all: $(EXEC)
@echo ------------------------ Compile Complete ----------------------------
.PHONY: clean depend
$(EXEC): $(OBJS)
$(CC) $(LFLAGS) -o $@ $^ $(LIBS)
.c.o:
$(CC) $(INC) -M $^
$(CC) $(CFLAGS) -o $@ $<
clean:
$(RM) *.o *~ $(EXEC) $(TAGS) $(BAK)
depend: $(SRCS)
makedepend $(INC) $^
it keeps saying that I it can't make a rule out of library.o 它一直在说我不能从library.o制定规则
plus I have another question 另外我还有一个问题
I acknowledge the fact that when Makefile comes in to action after calling 'make', 我承认,当Makefile在调用“ make”后生效时,
and subsequently go to the line .co or %c: %o(in GNU enhanced version) and make 然后转到行.co或%c:%o(在GNU增强版本中)并进行
.o files. .o文件。 but why doesn't it also call clean and depend automatically? 但是为什么它还不叫干净并自动依赖呢?
I've edited some things from the previous version of Makefile 我已经编辑了以前版本的Makefile中的一些内容
this time, (well pretty similar to the previous problem) even though I 这次,(非常类似于先前的问题)
clarified the library path(-I../lib), 阐明了库路径(-I ../ lib),
the Makefile cannot find the archive file (which I created as libmylib.a in ../lib dir) Makefile找不到存档文件(我在../lib目录中以libmylib.a创建)
now it's driving me crazy 现在让我发疯
but why doesn't it also call clean and depend automatically? 但是为什么它还不叫干净并自动依赖呢?
Because make
only builds the target you tell it. 因为make
只建立目标,所以您告诉它。 If you don't specify one, the first target is built, which in many cases, such as yours, is the 'all' target. 如果您未指定目标,则将建立第一个目标,在许多情况下,例如您的目标,将是“全部”目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.