检测C ++二进制文件是否已优化 [英] Detect if C++ binary is optimized

查看:112
本文介绍了检测C ++二进制文件是否已优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有标记或其他可靠的方法来检测编译后的C ++二进制文件是否经过优化编译?

Is there a flag or other reliable method to detect if a compiled C++ binary was compiled with optimizations?

我可以接受编译器特定的解决方案.

I'm okay with compiler-specific solutions.

编辑:这是用于构建部署系统的,该系统可能会意外地部署未正确构建的二进制文件.一个不漏水的解决方案是不可能的,但是如果可以在某些时候发现这种情况,它将节省一些痛苦(和金钱).

This is for a build deployment system, which could accidentally deploy binaries that were not built properly. A water-tight solution is unlikely, but it will save some pain (and money) if this can be detected some of the time.

编译器通常是gcc,有时是sun,如果有MSVC解决方案,我不想为了社区的利益而将其排除在外.

The compiler will often be gcc, sometimes sun, and if there's a MSVC solution, I don't want to rule that out for the benefit of the community.

推荐答案

GCC的最新版本具有

Recent versions of GCC have a way to report which flags were used to compile a binary (third bullet point).

有一个相关的命令行开关(--fverbose-asm),仅将汇编程序输出文件中的信息记录为注释,因此信息永远不会到达目标文件." --frecord-gcc-switches开关导致用于调用要记录到正在创建的目标文件中的编译器的命令行."

There is a related command line switch (--fverbose-asm) that "only records the information in the assembler output file as comments, so the information never reaches the object file." The --frecord-gcc-switches switch "causes the command line that was used to invoke the compiler to be recorded into the object file that is being created."

这篇关于检测C ++二进制文件是否已优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆