简体   繁体   English

我在项目中需要Makefile的帮助

[英]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.

相关问题 如何使我的 makefile 以我需要的方式将我的项目组合在一起? - How can I make my makefile put my project together the way I need it? 在排序链表时需要一些帮助 - Need some assistance with sorting a linked list “以下列表有什么问题?”我正在尝试学习函数,但需要一些帮助 - “What is wrong with the following listing?” I'm trying to learn functions but need some assistance 如何为我的C项目创建一个makefile? - How can I create a makefile for my C project? 需要一些帮助来了解char-&gt; ASCII和一些基础知识 - Need some assistance with understanding char->ASCII and some basics 我可以在与反向控制重复和 arguments 相关的作业上获得一些帮助吗? - Can I get some assistance with my homework having to do with counter-controlled repetition and arguments? 学习C,需要一些“Greedy”CS50解决方案的帮助 - Learning C, need some assistance with “Greedy” CS50 solution 为什么我需要运行我的makefile两次来编译我的代码 - Why do I need to run my makefile twice to compile my code 在将sqlite3包含到我的项目中时遇到麻烦,makefile无法执行我想要的操作 - Having trouble including sqlite3 into my project, makefile not doing what I want 我什么时候需要使用/拥有一个makefile文件? - When do I need to use/have a makefile?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM