使用带有gcc而不是clang的Makefile编译程序 [英] Compile program using a Makefile with gcc instead of clang

查看:204
本文介绍了使用带有gcc而不是clang的Makefile编译程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序来对给定的文本进行拼写检查.在我的电脑上,我使用了这个Makefile来编译程序:

I am writing a program to spell-check a given text. On my pc I used this Makefile to compile the program:

# 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?我尝试使用以下方式更改编译器:

I would like to continue programming on my Raspberry Pi but I only have gcc installed. Is it possible to make this Makefile work for gcc? I tried to change the compiler with:

CC = gcc

但是它不起作用.我收到错误消息无法识别的选项-Qunused-arguments".

but It doesn't work. I get the error message "unrecognised option -Qunused-arguments".

推荐答案

问题是Clang接受的-Q选项不是GCC认可的选项.

The problem is that the -Q option which Clang accepts isn't an option which GCC recognises.

GCC和Clang是完全独立的编译器,因此,一个人不应该真正期望其中一个了解另一个的选择.实际上,Clang确实做了一些努力以适度地与GCC兼容,很大程度上是为了使它可以用作GCC的替代产品.但是,这种兼容性不是完整的,也许也不应该是完整的.

GCC and Clang are completely separate compilers, and so one shouldn't really expect one of them to understand the other's options. In fact, Clang does make some efforts to be modestly compatible with GCC, in large part to make it possible to use it as a drop-in replacement for GCC. However that compatibility isn't, and probably shouldn't be, complete.

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

So your solution is simply to change the CFLAGS definition at the same time as you change the CC definition.

这篇关于使用带有gcc而不是clang的Makefile编译程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆