Makefile 无故删除目标文件 [英] Makefile removes object files for no reason
问题描述
这是 Makefile 代码:
Here is the Makefile code:
CC=gcc
CXX=g++
OBJS=OMXComponent.o Event.o hello_jpeg.o JPEG.o OMXCore.o Locker.o Logger.o
BIN=hello_jpeg.bin
# include ../Makefile.include
CFLAGS+=-DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi
LDFLAGS+=-L$(SDKSTAGE)/opt/vc/lib/ -lGLESv2 -lEGL -lopenmaxil -lbcm_host -lvcos -lvchiq_arm -lpthread -lrt -L../libs/ilclient -L../libs/vgfont
INCLUDES+=-I$(SDKSTAGE)/opt/vc/include/ -I$(SDKSTAGE)/opt/vc/include/interface/vcos/pthreads -I$(SDKSTAGE)/opt/vc/include/interface/vmcs_host/linux -I./ -I../libs/ilclient -I../libs/vgfont
all: $(BIN) $(LIB)
%.o: %.c
@rm -f $@
$(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations
%.o: %.cpp
@rm -f $@
$(CXX) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations
%.bin: $(OBJS)
$(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic
我不知道为什么,但是突然当我调用我的 Makefile 时,它开始删除所有的目标文件!!!之前没有删除,但最近在运行 Makefile 之后,这是我在控制台窗口中得到了什么:
I am not sure why, but suddenly when I am calling my Makefile, it started deleting all the object files !!! It was not deleting before, but lately after running the Makefile, this is what I get in the console window:
rm OMXCore.o JPEG.o OMXComponent.o Logger.o hello_jpeg.o Locker.o Event.o
知道它为什么要删除我的目标文件吗?以及如何阻止 Make 删除它?更奇怪的是,它昨天没有删,今天就开始了,没有我做任何升级,也没有做任何改动!!!现在,当我对我的一个 src 文件进行小改动时,现在我必须等待很长时间才能再次重建所有其他目标文件,这不是必需的,而且会减慢我的速度.
Any idea why it is removing my object files? and how to stop Make from deleting it? What is even more strange is that it was not deleting it yesterday, and it all started today, without me doing any upgrades or making any changes!!! Now when I make a small change in one of my src files, now I have to wait a long time for all the other object files to rebuilt again, which is not necessary and it slows me down.
我正在确保我在正确的目录中,我什至给了make"一个完整的路径,以防它选择不同的 Makefile
I am making sure that I am in the correct directory, I even gave "make" a complete path, in case if it is picking up a different Makefile
make -f/my_full_path/Makefile
make -f /my_full_path/Makefile
在 Makefile 运行时,我在另一个终端中执行ls",我注意到我正在正确累积目标文件,如下所示:
While Makefile was running, I was doing "ls" in a different terminal, and I noticed that I am correctly accumulating object files, as below:
-rw-rw-r-- 1 pi pi 1170 Mar 3 19:28 Makefile
-rw-r--r-- 1 pi pi 482052 Mar 3 19:30 OMXComponent.o
-rw-r--r-- 1 pi pi 19984 Mar 3 19:30 Event.o
-rw-r--r-- 1 pi pi 14688 Mar 3 19:30 hello_jpeg.o
-rw-r--r-- 1 pi pi 162260 Mar 3 19:31 JPEG.o
-rw-r--r-- 1 pi pi 215492 Mar 3 19:31 OMXCore.o
-rw-r--r-- 1 pi pi 76384 Mar 3 19:31 Locker.o
-rw-r--r-- 1 pi pi 0 Mar 3 19:31 Logger.o
但是突然之间,在所有东西都构建好之后,所有的目标文件都被删除了!!!
But all of a sudden, after everything is built, all the object files get removed !!!
而且,这是 Makefile 命令的输出:
And, here is the output of the Makefile command:
pi@raspberrypi /opt/vc/src/hello_pi/hello_jpeg_v2 $ make -f /opt/vc/src/hello_pi/hello_jpeg_v2/Makefile
g++ -g -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I./ -I../libs/ilclient -I../libs/vgfont -g -c OMXComponent.cpp -o OMXComponent.o -Wno-deprecated-declarations
g++ -g -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I./ -I../libs/ilclient -I../libs/vgfont -g -c Event.cpp -o Event.o -Wno-deprecated-declarations
g++ -g -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I./ -I../libs/ilclient -I../libs/vgfont -g -c hello_jpeg.cpp -o hello_jpeg.o -Wno-deprecated-declarations
g++ -g -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I./ -I../libs/ilclient -I../libs/vgfont -g -c JPEG.cpp -o JPEG.o -Wno-deprecated-declarations
g++ -g -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I./ -I../libs/ilclient -I../libs/vgfont -g -c OMXCore.cpp -o OMXCore.o -Wno-deprecated-declarations
g++ -g -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I./ -I../libs/ilclient -I../libs/vgfont -g -c Locker.cpp -o Locker.o -Wno-deprecated-declarations
g++ -g -DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi -I/opt/vc/include/ -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux -I./ -I../libs/ilclient -I../libs/vgfont -g -c Logger.cpp -o Logger.o -Wno-deprecated-declarations
g++ -g -o hello_jpeg.bin -Wl,--whole-archive OMXComponent.o Event.o hello_jpeg.o JPEG.o OMXCore.o Locker.o Logger.o -L/opt/vc/lib/ -lGLESv2 -lEGL -lopenmaxil -lbcm_host -lvcos -lvchiq_arm -lpthread -lrt -L../libs/ilclient -L../libs/vgfont -Wl,--no-whole-archive -rdynamic
rm OMXCore.o JPEG.o OMXComponent.o Logger.o hello_jpeg.o Locker.o Event.o
推荐答案
这些文件正在被删除,因为 make
认为它们是中间"的.当 make
形成一条规则链以产生先决条件时,它将中间链创建的所有文件视为中间",并在创建目标时删除.请参阅 GNU make 手册中的 链式规则.
The files are being removed because make
considers them "intermediate". When make
forms a chain of rules to produce a prerequisite, it treats all files created by the intermediate chains as "intermediate" and removes then when the target is created. See Chained Rules in the manual for GNU make.
在您的情况下,您可以通过两种方式防止这种情况:摆脱 %.bin
规则,无论如何这似乎是错误的,因为它说 all .bin
文件依赖于固定的目标文件列表,并将其替换为
In your case, you can prevent this in two ways: Get rid of the %.bin
rule, which seems wrong anyway, because it says that all .bin
files depend on a fixed list of object files, and replace it by
$(BIN): $(OBJS)
# as before
或将目标文件标记为次要":
or mark the object files as "secondary":
.SECONDARY: $(OBJS)
这篇关于Makefile 无故删除目标文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!