arm-linux-gnueabihf-g++ gcc编译、优化命令 汇总

这篇具有很好参考价值的文章主要介绍了arm-linux-gnueabihf-g++ gcc编译、优化命令 汇总。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

gcc优化选项,可在编译时间,目标文件长度,执行效率三个维度,进行不同的取舍和平衡。

gcc 常用编译选项

arm-linux-gnueabihf-g++ -O3 -march=armv7-a -mcpu=cortex-a9 -ftree-vectorize -mfpu=neon -mfpu=vfpv3-fp16 -mfloat-abi=hard -ffast-math 

-c 只编译并生成目标文件。
-E 只运行 C 预编译器。
-g 生成调试信息。GNU 调试器可利用该信息。
-Os 相对语-O2.5。
-o FILE 生成指定的输出文件。用在生成可执行文件时。
-O0 不进行优化处理。
-O 或 -O1 优化生成代码。
-O2 进一步优化。
-O3 比 -O2 更进一步优化,包括 inline 函数。
-shared 生成共享目标文件。通常用在建立共享库时。
-W 开启所有 gcc 能提供的警告。
-w 不生成任何警告信息。
-Wall 生成所有警告信息。

优化O0,O, O2, O3

These options control various sorts of optimizations.

Without any optimization option, the compiler’s goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent: if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program counter to any other statement in the function and get exactly the results you would expect from the source code.

Turning on optimization flags makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program.

The compiler performs optimization based on the knowledge it has of the program. Using the -funit-at-a-time flag will allow the compiler to consider information gained from later functions in the file when compiling a function. Compiling multiple files at once to a single output file (and using -funit-at-a-time) will allow the compiler to use information gained from all of the files when compiling each of them.

Not all optimizations are controlled directly by a flag. Only optimizations that have a flag are listed.

-O0

-O0: 不做任何优化,这是默认的编译选项。

-O1

-O1:优化会消耗少多的编译时间,它主要对代码的分支,常量以及表达式等进行优化。

-O和-O1: 对程序做部分编译优化,对于大函数,优化编译占用稍微多的时间和相当大的内存。使用本项优化,编译器会尝试减小生成代码的尺寸,以及缩短执行时间,但并不执行需要占用大量编译时间的优化。 -O1打开的优化选项, 可参考最后的参考文献。
Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function.
With -O, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time.

-O turns on the following optimization flags:

      -fdefer-pop 
      -fmerge-constants 
      -fthread-jumps 
      -floop-optimize 
      -fif-conversion 
      -fif-conversion2 
      -fdelayed-branch 
      -fguess-branch-probability 
      -fcprop-registers

-O also turns on -fomit-frame-pointer on machines where doing so does not interfere with debugging.

-O2

-O2:会尝试更多的寄存器级的优化以及指令级的优化,它会在编译期间占用更多的内存和编译时间。
Gcc将执行几乎所有的不包含时间和空间折中的优化。当设置O2选项时,编译器并不进行循环打开()loop unrolling以及函数内联。
Optimize even more. GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. The compiler does not perform loop unrolling or function inlining when you specify -O2. As compared to -O, this option increases both compilation time and the performance of the generated code.
-O2 turns on all optimization flags specified by -O. It also turns on the following optimization flags:

      -fforce-mem 
      -foptimize-sibling-calls 
      -fstrength-reduce 
      -fcse-follow-jumps  -fcse-skip-blocks 
      -frerun-cse-after-loop  -frerun-loop-opt 
      -fgcse  -fgcse-lm  -fgcse-sm  -fgcse-las 
      -fdelete-null-pointer-checks 
      -fexpensive-optimizations 
      -fregmove 
      -fschedule-insns  -fschedule-insns2 
      -fsched-interblock  -fsched-spec 
      -fcaller-saves 
      -fpeephole2 
      -freorder-blocks  -freorder-functions 
      -fstrict-aliasing 
      -funit-at-a-time 
      -falign-functions  -falign-jumps 
      -falign-loops  -falign-labels 
      -fcrossjumping

Please note the warning under -fgcse about invoking -O2 on programs that use computed gotos.

-O3

-O3: 在O2的基础上进行更多的优化。例如使用伪寄存器网络,普通函数的内联,以及针对循环的更多优化。在包含了O2所有的优化的基础上,又打开了以下优化选项:
l -finline-functions:内联简单的函数到被调用函数中。
l -fweb:构建用于保存变量的伪寄存器网络。 伪寄存器包含数据, 就像他们是寄存器一样, 但是可以使用各种其他优化技术进行优化, 比如cse和loop优化技术。这种优化会使得调试变得更加的不可能,因为变量不再存放于原本的寄存器中。
l -frename-registers:在寄存器分配后,通过使用registers left over来避免预定代码中的虚假依赖。这会使调试变得非常困难,因为变量不再存放于原本的寄存器中了。
l -funswitch-loops:将无变化的条件分支移出循环,取而代之的将结果副本放入循环中。

-Os

-Os:相当于-O2.5。是使用了所有-O2的优化选项,但又不缩减代码尺寸的方法。
Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.
-Os disables the following optimization flags:

      -falign-functions  -falign-jumps  -falign-loops 
      -falign-labels  -freorder-blocks  -fprefetch-loop-arrays

If you use multiple -O options, with or without level numbers, the last such option is the one that is effective.文章来源地址https://www.toymoban.com/news/detail-654126.html

Reference

  1. gcc Options That Control Optimization
  2. gcc编译优化-O0 -O1 -O2 -O3 -OS说明

到了这里,关于arm-linux-gnueabihf-g++ gcc编译、优化命令 汇总的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 交叉编译器 arm-linux-gnueabi 和 arm-linux-gnueabihf 的区别

    自己之前一直没搞清楚这两个交叉编译器到底有什么问题,特意google一番,总结如下,希望能帮到道上和我有同样困惑的兄弟…… ABI: 二进制应用程序接口(Application Binary Interface (ABI) for the ARM Architecture) 在计算机中,应用二进制接口描述了应用程序(或者其他类型)和操作系统之

    2024年04月11日
    浏览(33)
  • 交叉编译工具链arm-linux-gnueabihf的安装-ubuntu 20.04

    http://t.csdn.cn/ZbjFX 建议直接在.bashrc文件作修改 ,修改方式相同 ( vi :视自己的编辑器而定) 因为我在修改profile文件后,环境变量生效,但是命令行的用户名等颜色高亮显示会消失;并且重启终端后,又需要再source一下profile。 但是将环境变量添加至.bashrc则不会出现这两个问题

    2024年02月11日
    浏览(34)
  • Ubuntu上搭建ARM Linux GCC交叉编译环境

    在Ubuntu操作系统上搭建ARM Linux GCC交叉编译环境是为了能够在x86架构的主机上编译运行适用于ARM架构的程序。本文将介绍详细的步骤以及相应的源代码。 安装必要的软件包 首先,我们需要安装一些必要的软件包,包括GCC、GNU Binutils和GDB。打开终端,运行以下命令来安装这些软

    2024年02月02日
    浏览(35)
  • 【ARM 嵌入式 编译系列 2.1 -- GCC 预处理命令 #error 和 #warning 详细介绍 】

    在C语言中, #error 和 #warning 预处理指令可以用于在编译时生成错误或警告信息,通常用于调试或当代码中某些条件未满足时提醒开发者。当这些指令被编译器处理时,会自动包含出现这些指令的文件名和行号,所以你可以清楚地看到问题出现的位置。 #error 当编译器遇到 #e

    2024年01月22日
    浏览(43)
  • arm-linux-gcc 找不到命令?

    2024年02月12日
    浏览(34)
  • Ubuntu 22.04 搭建arm-linux-gcc交叉编译环境

    如果使用的是64位的Ubuntu系统,建议直接安装64位的arm-linux-gcc交叉编译器 下载地址: https://pan.baidu.com/s/14-lQpsXuEyCcHNHcTXcOyA 提取码: 55at 0. 注意在终端进行粘贴的操作为【Ctrl+shift+v】!! 把下载好的安装包移动到根目录下的tmp目录中(/tmp):在【其他位置】中的【计算机】中找

    2024年02月05日
    浏览(56)
  • Linux GCC常用命令以及GCC编译器

    GCC 是编译工具,它的意思是 GNU C Compiler 。经过了这么多年的发展,GCC 已经不仅仅能支持 C 语言;它现在还支持 Ada 语言、C++ 语言、Java 语言、Objective C 语言、Pascal 语言、COBOL语言,以及支持函数式编程和逻辑编程的 Mercury 语言等等。而 GCC 也不再单只是 GNU C 语言编译器的意

    2024年02月05日
    浏览(35)
  • 下载较老版本或最新版本的ARM Linux gcc 交叉编译工具链

    如果开发的 ARM 平台比较的多,需要多个版本的 arm gcc 交叉编译工具链,那么如何获取较新版本的 arm gcc 交叉编译工具链呢? 速度较快的,也比较新的,就到 ARM 官方网站下载 下载地址: https://developer.arm.com/downloads/-/gnu-a GNU-A Downloads 最新的下载地址: https://developer.arm.com/do

    2024年02月14日
    浏览(39)
  • [linux]Ubuntu 18.04安装arm-linux-gcc交叉编译器的两种方法

    第一种:apt安装法: Ctrl+Alt+T弹出终端,使用如下命令进行arm-linux-gcc的安装:   使用如下命令进行arm-linux-g++的安装:   如果要卸载时使用如下命令进行移除,arm-linux-gcc的卸载:   arm-linux-g++的卸载:  第二种源码安装: 目前网上搜索发现,最多人安装的是4.4.3版本的

    2024年02月05日
    浏览(41)
  • arm-linux-gnueabihf工具安装

    比如[gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz],主要問題就是非常慢(https://releases.linaro.org/components/toolchain/binaries/7.5-2019.12/arm-linux-gnueabihf/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf.tar.xz) 先解压 将当前的bin目录添加到环境变量中,使用命令pwd 环境变量生效 查看设置的路径,

    2024年02月12日
    浏览(25)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包