简体   繁体   English

Makefile中的Cflags用法

[英]Cflags usage in makefile

I wanted to know the use of C FLAGS.In make file what does the below snippet means ? 我想知道C FLAGS的用法。在make文件中,以下代码段是什么意思?

CFLAGS=-00 -g 
${PROG}: ${OBJS}
${CC} ${CFLAGS} -o ${PROG} ${OBJS} ${LDFLAGS}

what does -00 defines ? -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 ##################

My question here is to basically understand whether that -00 is for static analysis ? 我的问题是基本了解-00是否用于静态分析? From make file i thinks its -00(two Zero ) 从make文件中,我认为它的-00(两个零)

You probably are using GCC as your C compiler (perhaps as a cross compiler ), and your compilation commands are run by make . 您可能使用GCC作为C编译器(也许是交叉编译器 ),并且编译命令由make运行。 So read the chapter about Invoking GCC . 因此,请阅读有关调用GCC的章节。 -O0 (that is a 0 digit at last) is for an optimize option which: -O0 (最后为0位数)用于以下优化选项

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

in your Makefile (if you want more optimizations , eg for benchmarking purposes, replace -O0 by -O2 or -O3 ). 在您的Makefile (如果您想进行更多优化 (例如,出于基准测试目的,请用-O2-O3替换-O0 ))。 The -g3 is a debugging option (to emit DWARF debugging information for the gdb debugger , which you should use). -g3调试选项(为gdb调试器发出DWARF调试信息,您应该使用它)。

Notice that -00 is not for static analysis! 注意, -00 不能用于静态分析! You could consider using specialized external static source analysis tools , like Frama-C or Clang Analyzer . 您可以考虑使用专门的外部静态源分析工具 ,例如Frama-CClang 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). 这些工具通常比经典编译要慢得多(但当然,任何编译器都在内部出于优化目的进行一些静态分析)。

Take also time to read the documentation of make (and probably of binutils , for your linker). 还花一些时间阅读make文档 (对于链接器,可能还有binutils文档 )。 I am not sure you want to keep your SUPPRESS_WARNINGS line (it smells bad). 我不确定您要保留SUPPRESS_WARNINGS行(闻起来不好)。 You might perhaps also use remake (also here ) to debug your Makefile . 您可能还可以使用remake (也在此处 )调试Makefile Be aware that GNU make has a lot of builtin rules that you could see with make -p and that you should use. 请注意,您可以使用make -p看到GNU make有很多内置规则,并且应该使用这些规则。 BTW, CFLAGS is known to some of these rules (so is a convention in Makefile -s about compilation flags passed for compiling C files). 顺便说一下, CFLAGS在其中一些规则中是众所周知的( Makefile -s中的一个约定是有关为编译C文件而传递的编译标志的约定 )。

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 ). 请注意,您可能会非常谨慎和简约地在源代码中(很少)添加一些编译指示函数属性 ,例如,禁用特定的警告或强制进行优化(仅针对少数几个函数 )。

In addition to the answer by Basile Starynkevitch , I'd like to add: 除了Basile Starynkevitch的回答之外 ,我还要添加:

In make file what does the below snippet means ? 在make文件中,以下代码段是什么意思?

CFLAGS=-00 -g

The above assigns -O0 -g (make debugging information work as expected, and add debugging information, respectively) to the CFLAGS variable. 上面为CFLAGS变量分配了-O0 -g (使调试信息按预期工作,并分别添加调试信息)。

${PROG}: ${OBJS}
        ${CC} ${CFLAGS} -o ${PROG} ${OBJS} ${LDFLAGS}

The above creates a compilation recipe for the file named in the variable PROG , with the files named in variable OBJS as prerequisites. 上面为变量PROG命名的文件创建了一个编译配方,以变量OBJS命名的文件为前提。 Note that the indentation uses TAB s, not spaces. 请注意,缩进使用TAB而不是空格。 (This forum converts tabs to spaces in code snippets, that's why you get spaces if you copy+paste the above to an editor.) (此论坛将制表符转换为代码段中的空格,这就是为什么将以上内容复制并粘贴到编辑器后会获得空格的原因。)

The way make interprets this, is as follows: First, all of the files listed in variable OBJS must be created (and new enough). make的解释方式如下:首先,必须创建(并足够新的)变量OBJS列出的所有文件。 Then, the command named in variable CC needs to be run, with parameters ${CFLAGS} -o ${PROG} ${OBJS} ${LDFLAGS}$ . 然后,需要使用变量${CFLAGS} -o ${PROG} ${OBJS} ${LDFLAGS}$运行以变量CC命名的命令。

For example, if CC=arm-linux-gcc , PROG=foobar , OBJS=foobar.o , and LDFLAGS=-lm , then to generate foobar , make needs to first ensure foobar.o exists and is new enough, and then run arm-linux-gcc -o foobar foobar.o -lm . 例如,如果CC=arm-linux-gccPROG=foobarOBJS=foobar.oLDFLAGS=-lmOBJS=foobar.o生成foobar ,make需要首先确保foobar.o存在并且足够新,然后运行arm-linux-gcc -o foobar foobar.o -lm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM