KEIL,未调用的函数怎么样才能不占程序空间
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS当程序中有未调用的函数时,KEIL 给出上述警告,
实际上这段函数也是占用程序空间的,函数中的变量也占用内存,而且当全局变量处理,KEIL 把未用调用的函数按中断函数方式处理。
我想请教大家,在不删除函数的情况下,有何办法实现 未调用的函数不占内存也不占程序FLASH呢?有没有相关的编译选项呢?谢谢! 你说他占用空间,依据是什么? 【1楼】 i55x
你说他占用空间,依据是什么?
————————————————————————————————————
回复:
注释掉未调用代码,编译结果:
Program Size: data=67.2 xdata=0 code=2924
未注释时的编译结果:
Program Size: data=77.3 xdata=0 code=3103 只能把它屏蔽掉,好听一点的办法是条件编译干掉它 条件编译就好了,这点在ucos上很常见,叫做可以剪裁 做成通用的函数,然后封装进库里,想用哪个调哪个。 条件编译方法挺好 条件编译+1 条件编译,加宏开关! 就像ASSERT一样 #if 0#endif注释 有优化选项的吧? C/C++选项中ONE ELF……选项选上就可以了 keil arm 下有办法,keil c51没发现相应的功能
Minimizing code size by eliminating unused functions during compilation
ARM Compiler toolchain v5.02 for µVision Using the Compiler
Home > Getting Started with the Compiler > Minimizing code size by eliminating unused functions during compilation
Minimizing code size by eliminating unused functions during compilation
To eliminate unused functions from your object files:
Compile your source code.
Use the linker option --feedback=filename to create a feedback file. By default, the type of feedback generated is for the elimination of unused functions.
Re-compile using the compiler option --feedback=filename to feed the feedback file to the compiler.
The compiler uses the feedback file generated by the linker to compile the source code in a way that enables the linker to subsequently discard the unused functions.
Note
To obtain maximum benefit from linker feedback, do a full compile and link at least twice. A single compile and link using feedback from a previous build is normally sufficient to obtain some benefit.
You can specify the --feedback=filename option even when no feedback file exists. This enables you to use the same build or make file regardless of whether a feedback file exists, for example:
armcc -c --feedback=unused.txt test.c -o test.o
armlink --feedback=unused.txt test.o -o test.axf
The first time you build the application, it compiles normally but the compiler warns you that it cannot read the specified feedback file because it does not exist. The link command then creates the feedback file and builds the image. Each subsequent compilation step uses the feedback file from the previous link step to remove any unused functions that are identified.
条件编译,正是 yj_yulin 发表于 2013-4-19 14:58 static/image/common/back.gif
keil arm 下有办法,keil c51没发现相应的功能
Minimizing code size by eliminating unused functions duri ...
摘自http://bbs.zlgmcu.com/dispbbs.asp?boardid=43&ID=21190
Keil使用"REMOVEUNUSED"就可以简单实现:
把target options中的device页中选上"Use LX51 ...",
最后在LX51 Misc页中的Misc Control中填入"REMOVEUNUSED",
确认后重新编译即可自动去掉未调用的函数。
【接着使用Keil的优化级别9将代码优化,还可以进一步节省程序空间:】
学习一下.... 感觉11楼的靠谱 不让编译进出就可以了,
反正我正在编写的一个工程中,现在还有很多还没有用上的函数,使用UNMOVEUNUSED后,体积就变小了,最重要的是没有那些烦人的警告。 16楼正解。只有通过这种方法告知编译器不要将未使用函数放入最终代码里。 讲的挺好的 有时间试试 好东西啊 本帖最后由 lswhome 于 2014-1-11 13:37 编辑
16楼的方法证实管用!!!同时谷歌浏览器的打印功能里直接就有另存为PDF的功能,非常方便哦,哇哈哈哈!!!!! 16楼的方法很好,学习下
另外条件编译也很一个很好的方法,在不动编程软件下最好的处理方式 16楼的办法不错 不过注释掉也可以哈 16楼的方法可行,但和直接去掉代码 仍有区别
代码会大几个字节 十六楼的方式有空试一下 {:biggrin:}谢谢16L的办法 chencc8 发表于 2013-5-3 13:41
摘自http://bbs.zlgmcu.com/dispbbs.asp?boardid=43&ID=21190
Keil使用"REMOVEUNUSED"就可以简单实现:
+10086 终于在这里找到好办法,太棒了! 这办法不错,在产品上验证下看看
标记,有空试一下 好方法啊!顶之! 顶16楼!这个方法好!我之前的方法也是将不用的函数注释掉! 标记一下。 使用16楼的办法,为什么编译后出现const 和code 2个参数,没设置前只有code? 不得不顶16楼!
然来有这么方便的方法。 MARK,16喽方法 chencc8 发表于 2013-5-3 13:41
摘自http://bbs.zlgmcu.com/dispbbs.asp?boardid=43&ID=21190
Keil使用"REMOVEUNUSED"就可以简单实现:
学习了!~
MARK,16喽方法 标记一下,呵呵。 {:biggrin:}标记一下,有用 mark一记 16方法看着不错,下次试试 16楼的方法是可以减小,但是还是要多出好几百字节 你用的是旧版本KEIL2吧,KEIL3或4都会优化掉的,包括没调用过的函数、全局变量 gshuang1 发表于 2014-8-20 21:27
你用的是旧版本KEIL2吧,KEIL3或4都会优化掉的,包括没调用过的函数、全局变量 ...
我这里用16楼方法不行。会报L121错误 Edesigner. 发表于 2017-11-16 11:35
我这里用16楼方法不行。会报L121错误
应该没有问题的,一直这么用,是不是没选择使用lx选项呢 keil 自动注释掉不使用代码 UNMOVEUNUSED
要选择 LX51
页:
[1]