Makefile的致命错误:无法创建OBJ / calc.o [英] Makefile Fatal error: can't create obj/calc.o
问题描述
我试图做一个makefile一个简单的计算器为大专以上项目。我需要它做的,我在网上搜索了教程和我最终发现了这个code:
I'm trying to make a makefile for a simple calculator for a college project. I need it done, and I've searched the web for tutorials and I eventually found this code:
IDIR =include
CC=gcc
CFLAGS=-I$(IDIR)
ODIR=obj
LDIR=lib
SDIR=src
LIBS=-lm
_DEPS = calc.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
_OBJ = calc.o libcalc.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
$(ODIR)/%.o: $(SDIR)/%.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
calc: $(OBJ)
gcc -o $@ $^ $(CFLAGS) $(LIBS)
.PHONY: clean
clean:
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
make命令的输出是
The output of the make command is
gcc -c -o obj/calc.o calc.c -I../include
Assembler messages:
Fatal error: can't create obj/calc.o: No such file or directory
make: *** [obj/calc.o] Error 1
我的教授给了我们不含铅,也没有说明这一点,所以我真的失去了。
My professor gave us no lead nor instruction to this, so I'm really lost.
我的项目分为三个文件夹: LIB
,的src
和包含
。 的src
包含项目,命名为 calc.c
,包括源
包含名为标题 calc.h
和 LIB
包含名为库 libcalc .C
。
My project is divided in three folders: lib
, src
and include
. src
contains the source for the project, named calc.c
, include
contains the header named calc.h
, and lib
contains the library named libcalc.c
.
编辑:我想通了这个错误,这是在的src
未创建 OBJ
目录。但是,它仍然没有工作。新的错误信息是:
I figured out this error, and it was that the obj
directory under src
wasn't created. However, it's still not working. The new error message is:
make: *** No rule to make target `obj/libcalc.o', needed by `calc'. Stop.
编辑2:我刚刚搬进从lib中libcalc.c到obj它工作得很好。不理想,但它确实是我所需要的。
EDIT 2: I just moved the libcalc.c from lib to obj and it worked fine. Not ideal, but it does what I need.
推荐答案
的 OBJ
目录不存在,那么 GCC
无法写入输出文件存在。
The obj
directory doesn't exist, so gcc
cannot write the output file there.
您可以从Makefile中自动创建它,但是这取决于你想要做什么,一个简单的的mkdir OBJ
可能是你所需要的。
You could create it automatically from the Makefile, but depending on what you want to do, a simple mkdir obj
might be all you need.
不过,它看起来像你从的src
目录中运行你的Makefile。有可能到头来你想从你的项目的根目录中运行它,并指定的src /
在需要的地方。你会希望为添加 SDIR
变量(或类似);确保删除 ../
在 LDIR
, IDIR
和 ODIR
在这种情况下。
However, it looks like you are running your Makefile from the src
directory. Chances are you want to run it from your project's root directory and specify src/
where needed. You'd want to add an SDIR
variable (or similar) for that; make sure to remove the ../
on LDIR
, IDIR
and ODIR
in that case.
例如,您目前使用。%,C
,使用 $(SDIR)/。%,C
代替,并适当移动你的Makefile。
For example, where you currently use %.c
, use $(SDIR)/%.c
instead, and move your Makefile appropriately.
这篇关于Makefile的致命错误:无法创建OBJ / calc.o的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!