为什么会写这一篇文章呢?是因为工作中遇到很诡异的情况,公司要求做一个封装C语言的静态库,真机debug版的静态库运行正常,而真机release版则出现问题(c代码中的参数运行发生变化或释放),所以异常,无奈,不知怎么解决~~~~各种调查,庆幸的是最后解决了
很多情况下我们开发测试都是在debug模式下运行开发的,然而发布程序后或者切换至release版本下 程序就会出现各种问题,也就是说debug版本运行正常,而release版本出现错误?
针对于这种情况可以更改targets的 optimization level设置,将release版本的optimization level改为none后就可以了
下面是关于优化的英语,英语很烂看不懂,留着慢慢研究吧
关于优化级别: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.