Makefile中的Cflags用法 [英] Cflags usage in makefile
问题描述
我想知道C FLAGS的用法.在make文件中,以下代码段是什么意思?
I wanted to know the use of C FLAGS.In make file what does the below snippet means ?
CFLAGS=-00 -g
${PROG}: ${OBJS}
${CC} ${CFLAGS} -o ${PROG} ${OBJS} ${LDFLAGS}
-00定义了什么?
############# Target type (Debug/Release) ##################
############################################################
TARGET_NAME=telematics
CFLAGS=-O0 -g
LinkDebug=-g -Xlinker -Map=$(TARGET_NAME)debug.map
LinkRelease=-O -s -Xlinker -Map=$(TARGET_NAME).map
SUPPRESS_WARNINGS=-Wno-write-strings -Wno-builtin-macro-redefined
COMMON_DEFINES = -DA5N2 -DLINUX_SYSTEM -DCT_2
C___DEFINES =
CPP_DEFINES = -std=c++11 -D_GLIBCXX_USE_C99 -DUSE_IOSTREAM -DOM_NO_TEMPLATES_USAGE -DOM_NO_FRAMEWORK_MEMORY_MANAGER
ConfigurationCPPCompileSwitches= $(SUPPRESS_WARNINGS) $(COMMON_DEFINES) $(CPP_DEFINES) $(INCLUDE_PATH) $(CFLAGS) -c
ConfigurationCCompileSwitches= $(SUPPRESS_WARNINGS) $(COMMON_DEFINES) $(C___DEFINES) $(INCLUDE_PATH) $(CFLAGS) -c
###### Commands & Flags ################
RM=/bin/rm -rf
MD=/bin/mkdir -p
CC=arm-linux-gcc
LIB_CMD=arm-linux-ar
LINK_CMD=$(CC)
LIB_FLAGS=rvu
######### Context macros ##################
我的问题是基本了解-00是否用于静态分析?从make文件中,我认为它的-00(两个零)
My question here is to basically understand whether that -00 is for static analysis ? From make file i thinks its -00(two Zero )
推荐答案
您可能正在使用 GCC 作为您的C编译器(可能是跨编译器),而您的编译命令由-O0
(最后是一个0
数字)用于
一个优化选项,其中:
You probably are using GCC as your C compiler (perhaps as a cross compiler), and your compilation commands are run by make
. So read the chapter about Invoking GCC. -O0
(that is a 0
digit at last) is for
an optimize option which:
减少编译时间并使调试产生预期的结果.这是默认值
reduce compilation time and make debugging produce the expected results. This is the default
我强烈建议您同时启用所有警告 . >
I strongly recommend also enabling all warnings so put
CFLAGS= -Wall -Wextra -O0 -g3
在您的Makefile
中(如果您想要更多的优化,例如用于基准测试,将-O0
替换为-O2
或-O3
). -g3
是调试选项(发出 DWARF 有关
in your Makefile
(if you want more optimizations, e.g. for benchmarking purposes, replace -O0
by -O2
or -O3
). The -g3
is a debugging option (to emit DWARF debugging information for the gdb
debugger, which you should use).
请注意,对于静态分析,-00
不是 !您可以考虑使用专门的外部静态源分析工具,例如语言分析器.这些工具通常比经典编译要慢得多(但是,出于优化目的,当然任何编译器都会在内部进行 some 静态分析).
Notice that -00
is not for static analysis! You could consider using specialized external static source analysis tools, like Frama-C or Clang Analyzer. These tools typically run much slower than a classical compilation (but of course any compiler is doing some static analysis internally for optimization purposes).
还花时间阅读 make
的文档(对于您的链接器,可能是 binutils ).我不确定您是否要保持SUPPRESS_WARNINGS
行(闻起来不好).您也许还可以使用重新制作(也可以是
Take also time to read the documentation of make
(and probably of binutils, for your linker). I am not sure you want to keep your SUPPRESS_WARNINGS
line (it smells bad). You might perhaps also use remake (also here) to debug your Makefile
. Be aware that GNU make
has a lot of builtin rules that you could see with make -p
and that you should use. BTW, CFLAGS
is known to some of these rules (so is a convention in Makefile
-s about compilation flags passed for compiling C files).
请注意,您可能会非常谨慎和简约地添加(很少)一些功能属性,例如,禁用特定的警告或强制进行优化(仅针对少数几个功能).
Notice that you might, with great care and parsimony, add (rarely) some pragmas or function attributes in your source code, for example to disable specific warnings or force optimizations (only on some very few functions).
这篇关于Makefile中的Cflags用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!