gpt4 book ai didi

c - 如何强制对每个 make 的所有文件进行完全重新编译?

转载 作者:行者123 更新时间:2023-12-02 04:20:45 24 4
gpt4 key购买 nike

我希望为小型 C 应用程序创建一个基本的 makefile 模板。在这种情况下,我更关心清晰度而不是性能,并且希望重新编译所有内容 - 所有 .h 和 .c 文件以及第三方 .so 文件。

# Constants
#===============================================================================

# Specify the C complier
CC = gcc

# List the flags to pass to the compiler
# -ggdb Compile with debug information for gdb
# -Wall Give all diagnostic warnings
# -O0 Do NOT optimize generated code
# -m64 Generate code for a 64-bit environment
CFLAGS = -ggdb -Wall -O0 -m64

# Change the list of c source files into a list of object files by replacing
# the .c suffix with .o
OBJECTS := $(patsubst %.c,%.o,$(wildcard *.c))

# List libraries
# m Math library
LIBRARIES = -lm

# Specify the build target
TARGET = heyyou

# Rules
#===============================================================================
# $@ = left side of the colon, the target
$(TARGET) : $(OBJECTS)
@echo "Compiling $@..."
$(CC) -o $(TARGET) $(OBJECTS) $(CFLAGS) $(LIBRARIES)

最佳答案

如果你已经正确地考虑了所有的礼仪而制作了 Makefile,只需使用

make clean

如果您创建了正确的 Makefile,所有依赖项都将自动处理,并且对于您在文件系统中所做的每项更改,您不必每次都执行“make clean”。一个简单的“make”就足够了。
如果您尚未处理 make 中的所有依赖项,那么您会注意到源代码中所做的更改不会反射(reflect)在二进制文件中。因此,解决此问题的一个简单方法是在 Makefile 中添加这些行

clean:
rm *.so
rm *.o

现在,对于每个编译,执行类似的操作

make clean 
make

这不是处理 Makefile 的正确方法,但它是某些令人沮丧的情况下的救世主。

关于c - 如何强制对每个 make 的所有文件进行完全重新编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30635962/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com