首页 > 代码库 > 解决部分在Debug模式下程序没问题但是Release模式下出现问题的方法
解决部分在Debug模式下程序没问题但是Release模式下出现问题的方法
编译策略介绍
关于优化级别:GCC_OPTIMIZATION_LEVEL 描述如下
None: Do not optimize.
[-O0]With this setting, 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.Fast: Optimizing compilation takes somewhat more time, and a lot more memory for a large function.
[-O, -O1]With this setting, the compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time. In Apple’s compiler, strict aliasing, block reordering, and inter-block scheduling are disabled by default when optimizing.Faster: The compiler performs nearly all supported optimizations that do not involve a space-speed tradeoff.
[-O2]With this setting, the compiler does not perform loop unrolling or function inlining, or register renaming. As compared to the ‘Fast’ setting, this setting increases both compilation time and the performance of the generated code.Fastest: Turns on all optimizations specified by the ‘Faster’ setting and also turns on function inlining and register renaming options. This setting may result in a larger binary.
[-O3]Fastest, smallest: Optimize for size. This setting enables all ‘Faster’ optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.
编译策略资料:
https://gcc.gnu.org/onlinedocs/gnat_ugn/Optimization-Levels.html
拓展问题
1.今天在测试app时,发现app store上版本有奔溃现象,但是直接用xcode跑本地程序没问题。猜测release&debug版本造成的,后发现targets的 optimization level设置问题,将release版本的optimization level改为none后程序不再崩溃
2.问答
问:写了个程序。但在release模式下真机测试 ,不能正常工作。例如界面从网络上获取的图片等等。 但当optimization level设置成NONE后所有问题都正常了。
发布到APPSTORE上的程序编译时必须设置optimization level为 [-Os] 吗?如果设置为NONE会不会不通过审核?
答:Optimization Level 应该是编译器的优化程度。
比较早期的时候,硬件资源是比较缺乏的。为了提高性能,开发编译器的大师们,都会对编译器(从c到汇编的编译过程)加上一定的优化策略。优化后的代码效率比较高,但是可读性比较差,且编译时间更长。
优化是指编译器一级的措施,与机器指令比较接近,所以很可能会导致硬件不兼容,进而产生了你目前遇到的软件装不上的问题。
他是编译器的行为,与你代码理论上不相关的。 苹果的检查应该是检查你的代码一级的规范程度,隐私侵权相关的问题。 应该是与编译的过程是无关的。请放心。
解决部分在Debug模式下程序没问题但是Release模式下出现问题的方法