gpt4 book ai didi

c++ - GNU 使 : A better way of using both C/C++ targets with different commands

转载 作者:太空宇宙 更新时间:2023-11-04 08:28:37 24 4
gpt4 key购买 nike

问:下面是我的 Makefile 片段:

SRCS+=$(wildcard *.c *.cpp)
OBJECTS=$(addprefix $(OBJ_DIR)/, $(patsubst %.c,%.o,$(SRCS:.cpp=.o)))
# .....
$(OBJ_DIR)/%.o: %.cpp
$(CXX) -ggdb -Wall -Wextra -Werror $(INC) $(C_FLAGS) -c -o $@ $<

$(OBJ_DIR)/%.o: %.c
$(CC) -ggdb -Wall -Wextra -Werror $(INC) $(C_FLAGS) -c -o $@ $<

如何在“OBJECTS”之后重构表达式并删除 .cpp 和 .%c 的相似规则的重复项?

最佳答案

OBJECTS := $(patsubst %,$(OBJ_DIR)/%.o,$(basename $(SRCS)))
# Note that you may not need this variable at all.

COMPILE_ARGS = -ggdb -Wall -Wextra -Werror $(INC) $(C_FLAGS) -c -o $@ $<

$(OBJ_DIR)/%.o: %.cpp
$(CXX) $(COMPILE_ARGS)

$(OBJ_DIR)/%.o: %.c
$(CC) $(COMPILE_ARGS)

关于c++ - GNU 使 : A better way of using both C/C++ targets with different commands,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29355150/

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