使用带有gcc而不是clang的Makefile编译程序

使用带有gcc而不是clang的Makefile编译程序,makefile,Makefile,我正在写一个程序来检查给定文本的拼写。在我的电脑上,我使用此Makefile编译程序: # compiler to use CC = clang # flags to pass compiler CFLAGS = -ggdb3 -O0 Qunused-arguments -std=c99 -Wall -Werror # name for executable EXE = speller # space-separated list of header files HDRS = dictio

我正在写一个程序来检查给定文本的拼写。在我的电脑上,我使用此Makefile编译程序:

# compiler to use
CC = clang

# flags to pass compiler
CFLAGS = -ggdb3 -O0 Qunused-arguments -std=c99 -Wall -Werror

# name for executable
EXE = speller

# space-separated list of header files
HDRS = dictionary.h

# space-separated list of source files
SRCS = speller.c dictionary.c

# automatically generated list of object files
OBJS = $(SRCS:.c=.o)

# default target
$(EXE): $(OBJS) $(HDRS) Makefile
    $(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS)

# dependencies
$(OBJS): $(HDRS) Makefile
我想继续在我的Raspberry Pi上编程,但我只安装了gcc。有可能使这个Makefile为gcc工作吗?我试图用以下方法更改编译器:

CC = gcc

但它不起作用。我收到错误消息“Unrecogned option-qused arguments”。

问题是Clang接受的
-Q
选项不是GCC识别的选项

GCC和Clang是完全独立的编译器,因此不应该期望其中一个能够理解另一个的选项。事实上,Clang确实做出了一些努力来适度兼容GCC,在很大程度上是为了使它能够作为GCC的替代品。然而,这种兼容性不是,也可能不应该是完整的


因此,您的解决方案只是在更改
CC
定义的同时更改
CFLAGS
定义

您已将
CC
调整为所需的编译器。现在,您需要调整编译器标志,以说明您正在使用不同的编译器。问题是等价的论点是什么?问题是如何在makefile中以自动方式处理这个问题?