[英]Makefile project won't build after no changes to makefile (near identical make, works fine)
就在昨天,我已經在Linux下編譯了一個makefile項目。 現在,該項目將無法編譯,我不記得對makefile本身進行了任何更改。 它拋出一個make: *** No rule to make target 'obj/TranquilMain.o', needed by 'tranquil;. Stop.
make: *** No rule to make target 'obj/TranquilMain.o', needed by 'tranquil;. Stop.
在make
錯誤。 我所做的唯一真正的更改是,當我從另一個項目復制代碼和makefile時,我更改了某些文件的名稱(包括依賴項),然后更改了makefile中的_DEPS
。 所有文件都在必要的位置。
應該注意的是,如果我從_OBJ列表中刪除了TranquilMain.o以外的所有其他文件,它可以正常編譯。 enter code here
我希望我能提供的不僅僅是代碼和這種知識,但是我不知道問題出在哪里。
適當的Makefile:“ makefile”
#!/usr/bin/make
CC = gcc
CP = g++
SRC_DIR = #.
OBJ_DIR = obj
INC_DIR = ../include
LIB_DIR = ../lib
LIBS = -lm -lSDL -lSDLmain -lSDL_image -lSDL_mixer -lSDL_ttf -lSDL_net -lGL -lGLU -lGLEW
CFLAGS = -I$(INC_DIR) -L$(LIB_DIR) -std=gnu++0x
_DEPS = DefaultConfig.h BaseApplication.h BasePlugin.h SDLImage.h SDLFont.h SDLWindow.h SDLInput.h SDLRenderer.h SDLApplication.h Math2D.h SDLTimer.h
DEPS = $(patsubst %,$(INC_DIR)/%,$(_DEPS))
_OBJ = TranquilMain.o BaseApplication.o BasePlugin.o SDLImage.o SDLFont.o SDLWindow.o SDLInput.o SDLRenderer.o SDLApplication.o Math2D.o SDLTimer.o
OBJ = $(patsubst %,$(OBJ_DIR)/%,$(_OBJ))
$(OBJ_DIR)/%.o: %.cpp $(DEPS)
$(CP) -c -o $@ $< $(CFLAGS)
tranquil: $(OBJ)
$(CP) -o ../bin/$@ $^ $(CFLAGS) $(LIBS)
.PHONY: clean
clean:
rm -f $(OBJ_DIR)/*.o *~ core $(INC_DIR)/*~
顯然沒用的TranquilMain.cpp(只是依賴項中的第一個文件)
#include <iostream>
#include <fstream>
#include <string>
int main( int argc, char* args[] )
{
bool running = true;
while( running == true )
{
}
return 0;
}
當我從上面的Makefile和項目結構開始時
├── include/
└── src/
├── Makefile
├── TranquilMain.cpp
└── obj/
然后,我得到相同的名稱make: *** No rule to make target `obj/TranquilMain.o', needed by `tranquil'.
您在上面報告的錯誤。 是什么原因造成的? 讓我們在調試模式下運行make進行查找。
首先添加
.SUFFIXES:
%:: SCCS/s.%
%:: RCS/%
%:: RCS/%,v
%:: %,v
%:: s.%
到Makefile的頂部以取消一些只會使調試輸出混亂的默認規則。
然后,運行make -d
:
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin11.3.0
Reading makefiles...
Reading makefile `Makefile'...
Updating makefiles....
Considering target file `Makefile'.
Looking for an implicit rule for `Makefile'.
No implicit rule found for `Makefile'.
Finished prerequisites of target file `Makefile'.
No need to remake target `Makefile'.
Updating goal targets....
Considering target file `tranquil'.
File `tranquil' does not exist.
Considering target file `obj/TranquilMain.o'.
File `obj/TranquilMain.o' does not exist.
Looking for an implicit rule for `obj/TranquilMain.o'.
Trying pattern rule with stem `TranquilMain'.
Trying implicit prerequisite `TranquilMain.cpp'.
Trying rule prerequisite `../include/DefaultConfig.h'.
Trying pattern rule with stem `TranquilMain'.
Trying implicit prerequisite `TranquilMain.cpp'.
Trying rule prerequisite `../include/DefaultConfig.h'.
Looking for a rule with intermediate file `../include/DefaultConfig.h'.
Avoiding implicit rule recursion.
No implicit rule found for `obj/TranquilMain.o'.
Finished prerequisites of target file `obj/TranquilMain.o'.
Must remake target `obj/TranquilMain.o'.
make: *** No rule to make target `obj/TranquilMain.o', needed by `tranquil'. Stop.
make
首先確保的Makefile
是最新的。 然后,它嘗試通過執行深度優先搜索並建立所有必需的依賴關系來使目標tranquil
。 tranquil
取決於${OBJ}
,其第一個元素是obj/TranquilMain.o
。 根據${OBJDIR}/%.o
規則,這取決於TranquilMain.cpp
和所有${DEPS}
。 的第一個元素${DEPS}
是../include/DefaultConfig.h
,這樣make
嘗試構建它。 但是它不存在,也沒有構建它的規則。 make
得出結論,由於缺少依賴項,因此無法使用此規則構建obj/TranquilMain.o
。 它試圖找到另一個規則來使用確實存在的其他依賴項來構建它,但是沒有這樣的規則。 所以make
停,說:“沒有[有效期]規則[將存在相關性或可建]使目標obj/TranquilMain.o
。”
有什么解決方案? 確保所有依賴項都存在。 使用此Makefile,要編譯任何內容,您的項目必須至少包含:
.
├── include/
│ ├── BaseApplication.h
│ ├── BasePlugin.h
│ ├── DefaultConfig.h
│ ├── Math2D.h
│ ├── SDLApplication.h
│ ├── SDLFont.h
│ ├── SDLImage.h
│ ├── SDLInput.h
│ ├── SDLRenderer.h
│ ├── SDLTimer.h
│ └── SDLWindow.h
├── lib/
└── src/
├── BaseApplication.cpp
├── BasePlugin.cpp
├── Makefile
├── Math2D.cpp
├── SDLApplication.cpp
├── SDLFont.cpp
├── SDLImage.cpp
├── SDLInput.cpp
├── SDLRenderer.cpp
├── SDLTimer.cpp
├── SDLWindow.cpp
├── TranquilMain.cpp
└── obj/
您可能還需要將庫文件添加到lib/
以獲取最終的可執行文件。
另外,請確保您沒有無意間將制表符變成空白。
規則必須以“標簽”開頭:
#BAD!
tranquil: $(OBJ)
<space><space>$(CP) -o ../bin/$@ $^ $(CFLAGS) $(LIBS)
#GOOD!
tranquil: $(OBJ)
<tab>$(CP) -o ../bin/$@ $^ $(CFLAGS) $(LIBS)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.