CFLAGS,CCFLAGS,CXXFLAGS - 这些变量究竟控制着什么? [英] CFLAGS, CCFLAGS, CXXFLAGS - what exactly do these variables control?
问题描述
我使用GNU make来编译我的C ++代码,并且我想知道如何使我的编译可定制。
我在不同的地方阅读 CFLAGS
, CCFLAGS
和 CXXFLAGS
用于此目的。那么我应该如何使用它们?如果我有更多的命令行参数给编译器,我应该把它们追加到 CFLAGS
或者预先加入它们吗?有没有普遍的做法?
为什么三个不同的变量?我想C编译器应该得到 设置这些变量呢?做任何自动工具( 目前我的Makefile看起来像这样,我觉得它有点儿dirty: 我很确定这里没有错误; Makefile工作得很好。但是有没有违背约定的东西(比如 对不起,有这么多问题;你显然不会回答他们,但我希望这些答案能帮助我理解这些设置背后的总体思路。 名字的唯一理由是默认的make规则,通过 如果你编写所有你自己的规则,选择所有你自己的宏名称。 在vanilla gnu make中,没有CCFLAGS这样的东西。有 为什么 I am using GNU make to compile my C++ code, and i would like to understand how to make my compilations customizable. I read in different places that Why the three different variables? I suppose the C compiler should get Is the human user supposed to set these variables at all? Do any automatic tools ( Currently my Makefile looks like this, and i feel it's a bit dirty: I am pretty sure there are no bugs here; the Makefile works very well. But is there anything that goes against conventions (like Sorry for so many questions; you will obviously not answer them all but i hope the answers will help me understand the general idea behind these settings. As you noticed, these are Makefile {macros or variables}, not compiler options. They implement a set of conventions. (Macros is an old name for them, still used by some. GNU make doc calls them variables.) The only reason that the names matter is the default make rules, visible via If you write all your own rules, you get to pick all your own macro names. In a vanilla gnu make, there's no such thing as CCFLAGS. There are Why is 这篇关于CFLAGS,CCFLAGS,CXXFLAGS - 这些变量究竟控制着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! CFLAGS
和 CCFLAGS
,而C ++编译器应该得到 CFLAGS 和
CXXFLAGS
- 我是否正确?
automake
, autoconf
等)设置它们?我应该使用的linux系统没有定义任何这些变量 - 这是典型的吗?
ifdef code_coverage
GCOV_FLAG:= -fprofile-arcs -ftest-coverage
else
GCOV_FLAG:=
endif
WFLAGS:= -Wall
INC_FLAGS:= -Istuff -Imore_stuff -Ietc
CCFLAGSINT: = -O3 $(WFLAGS)$(INC_FLAGS)$(CCFLAGS)
...(makefile中的某处,编译命令行如下所示)
$(CC) $(CCFLAGSINT)-c $ < -o $ @
...(makefile中的某处,链接的命令行如下所示)
$(CC)$(GCOV_FLAG)$(CCFLAGSINT)$(OBJLIST )$(LDFLAGS)-o $ @
CCFLAGSINT
- 我应该重写 CCFLAGS
),还是 CXXFLAGS
?FUD!)
make -p
可以看到,它们使用了其中的一些。
CFLAGS
, CPPFLAGS
和 CXXFLAGS
。 C编译器的 CFLAGS
,C ++的 CXXFLAGS
,以及 CPPFLAGS
for each。
CPPFLAGS
都在?通常,它是预处理器标志( -D
, -U
)的起源,并且c和c ++都使用它们。现在,假设每个人都希望为c和c ++定义相同的环境,这可能是有问题的,但却是传统的。CFLAGS
, CCFLAGS
and CXXFLAGS
are used for this purpose. So how should i use them? If i have additional command-line arguments to the compiler, should i append them to CFLAGS
or prepend them? Is there a common practice?CFLAGS
and CCFLAGS
, while the C++ compiler should get CFLAGS
and CXXFLAGS
- did i get it right?automake
, autoconf
, etc) set them? The linux system that i am supposed to use doesn't define any of these variables - is this typical?ifdef code_coverage
GCOV_FLAG := -fprofile-arcs -ftest-coverage
else
GCOV_FLAG :=
endif
WFLAGS := -Wall
INC_FLAGS := -Istuff -Imore_stuff -Ietc
CCFLAGSINT := -O3 $(WFLAGS) $(INC_FLAGS) $(CCFLAGS)
... (somewhere in the makefile, the command-line for compilation looks like this)
$(CC) $(CCFLAGSINT) -c $< -o $@
... (somewhere in the makefile, the command-line for linking looks like this)
$(CC) $(GCOV_FLAG) $(CCFLAGSINT) $(OBJLIST) $(LDFLAGS) -o $@
CCFLAGSINT
- should i just overwrite CCFLAGS
instead? Or CXXFLAGS
? FUD!)make -p
, which use some of them.CFLAGS
, CPPFLAGS
, and CXXFLAGS
. CFLAGS
for the C compiler, CXXFLAGS
for C++, and CPPFLAGS
for both.CPPFLAGS
in both? Conventionally, it's the home of preprocessor flags (-D
, -U
) and both c and c++ use them. Now, the assumption that everyone wants the same define environment for c and c++ is perhaps questionable, but traditional.