默认gcc编译器选项是特定于gcc版本还是特定于操作系统或两者兼有?

时间:2022-03-23 07:02:27

I am wondering if the default gcc compiler options can vary any if so where I can expect different default compiler options. Do default compiler options vary from one gcc version to another (e.g gcc 4.6 -> gcc 4.8)or are they always the same? Do default compiler options vary from one OS version to another (e.g. Ubuntu 12.04 -> 14.04)?

我想知道默认的gcc编译器选项是否可以改变,如果是这样,我可以期望不同的默认编译器选项。默认编译器选项是否从一个gcc版本到另一个版本(例如gcc 4.6 - > gcc 4.8)或它们是否始终相同?默认编译器选项是否因OS版本而异(例如Ubuntu 12.04 - > 14.04)?

I expect that default compiler options are different regarding two different OS, like Ubuntu and Debian, right?

我希望默认的编译器选项在两个不同的OS上是不同的,比如Ubuntu和Debian,对吗?

2 个解决方案

#1


3  

Yes, you can generally expect the default flags to be quite different. Fortunately, you don't need to know what the flags are, and you don't need to set them.

是的,您通常可以预期默认标志会完全不同。幸运的是,您不需要知道标志是什么,也不需要设置它们。

Ubuntu and Debian are pretty similar, since Ubuntu is so closely based on Debian. But you will see a variety of different options, since the actual options that GCC uses are fairly technical. You can see them by running the following:

Ubuntu和Debian非常相似,因为Ubuntu非常依赖Debian。但是你会看到各种不同的选择,因为GCC使用的实际选项是相当技术性的。您可以通过运行以下命令来查看它们:

gcc -Q -v -x c -c /dev/null

This asks GCC to compile /dev/null as a C program (-x c -c /dev/null) and print out a bunch of developer info (-Q -v). I ran this with GCC 4.4, 4.6, and 4.8 and got different results. Here are the differences between the options for 4.4 and 4.6 on my machine:

这要求GCC将/ dev / null编译为C程序(-x c -c / dev / null)并打印出一堆开发人员信息(-Q -v)。我用GCC 4.4,4.6和4.8运行了这个并得到了不同的结果。以下是我的机器上4.4和4.6的选项之间的差异:

< -falign-loops
< -fargument-alias
> -fdelete-null-pointer-checks
> -fprefetch-loop-arrays
> -fsched-critical-path-heuristic
> -fsched-dep-count-heuristic
> -fsched-group-heuristic
> -fsched-last-insn-heuristic
> -fsched-rank-heuristic
> -fsched-spec-insn-heuristic
> -fshow-column
> -fstrict-volatile-bitfields
> -ftree-forwprop
> -ftree-loop-if-convert
> -ftree-phiprop
> -ftree-pta
> -ftree-slp-vectorize
> -fvar-tracking-assignments
< -mfused-madd

Here are the diffs from version 4.6 to 4.8 on my machine:

以下是我机器上版本4.6到4.8的差异:

> -faggressive-loop-optimizations
> -fgnu-runtime
> -fgnu-unique
< -finline-functions-called-once
> -finline-atomics
> -fira-hoist-pressure
> -fsync-libcalls
> -ftree-coalesce-vars
< -fvect-cost-model
> -mfxsr
> -mlong-double-80

On my machine, GCC uses 80 different options by default when compiling C! The options will also change when you compile C++ or compile on different platforms.

在我的机器上,GCC在编译C时默认使用80个不同的选项!在编译C ++或在不同平台上编译时,这些选项也会发生变化。

But that's okay. You can basically ignore all of these options and just focus on the most important ones, which are the various -W warning flags, -O optimization flags (which are really just shortcuts for a ton of preselected -f flags and a few -m—on my computer, -O2 enables 63 additional flags!), and the -g debug data flag.

但那没关系。您基本上可以忽略所有这些选项,只关注最重要的选项,即各种-W警告标志,-O优化标志(实际上只是大量预先选择的-f标志和几个-m-的快捷方式)在我的计算机上,-O2启用了63个额外的标志!)和-g调试数据标志。

And of course, the basic flags, like -std=, -c, -o, -l, -I, etc.

当然还有基本的标志,比如-std =, - c,-o,-l,-I等。

I mean, do you really need to know what -fbranch-count-reg does? Not really.

我的意思是,你真的需要知道-fbranch-count-reg是做什么的吗?不是真的。

#2


0  

I would recommend that you take advantage of tools such as automake to build the Makefiles for your application. This tool can build the files in different ways depending on environment. Then, within that Makefile, specify the options that are important to you: do not leave them to defaults ("to chance").

我建议您利用automake等工具为您的应用程序构建Makefile。此工具可以根据环境以不同方式构建文件。然后,在该Makefile中,指定对您很重要的选项:不要将它们保留为默认值(“to chance”)。

#1


3  

Yes, you can generally expect the default flags to be quite different. Fortunately, you don't need to know what the flags are, and you don't need to set them.

是的,您通常可以预期默认标志会完全不同。幸运的是,您不需要知道标志是什么,也不需要设置它们。

Ubuntu and Debian are pretty similar, since Ubuntu is so closely based on Debian. But you will see a variety of different options, since the actual options that GCC uses are fairly technical. You can see them by running the following:

Ubuntu和Debian非常相似,因为Ubuntu非常依赖Debian。但是你会看到各种不同的选择,因为GCC使用的实际选项是相当技术性的。您可以通过运行以下命令来查看它们:

gcc -Q -v -x c -c /dev/null

This asks GCC to compile /dev/null as a C program (-x c -c /dev/null) and print out a bunch of developer info (-Q -v). I ran this with GCC 4.4, 4.6, and 4.8 and got different results. Here are the differences between the options for 4.4 and 4.6 on my machine:

这要求GCC将/ dev / null编译为C程序(-x c -c / dev / null)并打印出一堆开发人员信息(-Q -v)。我用GCC 4.4,4.6和4.8运行了这个并得到了不同的结果。以下是我的机器上4.4和4.6的选项之间的差异:

< -falign-loops
< -fargument-alias
> -fdelete-null-pointer-checks
> -fprefetch-loop-arrays
> -fsched-critical-path-heuristic
> -fsched-dep-count-heuristic
> -fsched-group-heuristic
> -fsched-last-insn-heuristic
> -fsched-rank-heuristic
> -fsched-spec-insn-heuristic
> -fshow-column
> -fstrict-volatile-bitfields
> -ftree-forwprop
> -ftree-loop-if-convert
> -ftree-phiprop
> -ftree-pta
> -ftree-slp-vectorize
> -fvar-tracking-assignments
< -mfused-madd

Here are the diffs from version 4.6 to 4.8 on my machine:

以下是我机器上版本4.6到4.8的差异:

> -faggressive-loop-optimizations
> -fgnu-runtime
> -fgnu-unique
< -finline-functions-called-once
> -finline-atomics
> -fira-hoist-pressure
> -fsync-libcalls
> -ftree-coalesce-vars
< -fvect-cost-model
> -mfxsr
> -mlong-double-80

On my machine, GCC uses 80 different options by default when compiling C! The options will also change when you compile C++ or compile on different platforms.

在我的机器上,GCC在编译C时默认使用80个不同的选项!在编译C ++或在不同平台上编译时,这些选项也会发生变化。

But that's okay. You can basically ignore all of these options and just focus on the most important ones, which are the various -W warning flags, -O optimization flags (which are really just shortcuts for a ton of preselected -f flags and a few -m—on my computer, -O2 enables 63 additional flags!), and the -g debug data flag.

但那没关系。您基本上可以忽略所有这些选项,只关注最重要的选项,即各种-W警告标志,-O优化标志(实际上只是大量预先选择的-f标志和几个-m-的快捷方式)在我的计算机上,-O2启用了63个额外的标志!)和-g调试数据标志。

And of course, the basic flags, like -std=, -c, -o, -l, -I, etc.

当然还有基本的标志,比如-std =, - c,-o,-l,-I等。

I mean, do you really need to know what -fbranch-count-reg does? Not really.

我的意思是,你真的需要知道-fbranch-count-reg是做什么的吗?不是真的。

#2


0  

I would recommend that you take advantage of tools such as automake to build the Makefiles for your application. This tool can build the files in different ways depending on environment. Then, within that Makefile, specify the options that are important to you: do not leave them to defaults ("to chance").

我建议您利用automake等工具为您的应用程序构建Makefile。此工具可以根据环境以不同方式构建文件。然后,在该Makefile中,指定对您很重要的选项:不要将它们保留为默认值(“to chance”)。