搜索
bottom↓
回复: 50

KEIL,未调用的函数怎么样才能不占程序空间

  [复制链接]

出0入0汤圆

发表于 2011-10-29 19:25:18 | 显示全部楼层 |阅读模式
*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
当程序中有未调用的函数时,KEIL 给出上述警告,
实际上这段函数也是占用程序空间的,函数中的变量也占用内存,而且当全局变量处理,KEIL 把未用调用的函数按中断函数方式处理。

我想请教大家,在不删除函数的情况下,有何办法实现 未调用的函数不占内存也不占程序FLASH呢?有没有相关的编译选项呢?谢谢!

出0入0汤圆

发表于 2011-10-29 19:41:44 | 显示全部楼层
你说他占用空间,依据是什么?

出0入0汤圆

 楼主| 发表于 2011-10-29 19:45:45 | 显示全部楼层
【1楼】 i55x     
       你说他占用空间,依据是什么?
————————————————————————————————————
回复:
注释掉未调用代码,编译结果:
Program Size: data=67.2 xdata=0 code=2924

未注释时的编译结果:
Program Size: data=77.3 xdata=0 code=3103

出0入0汤圆

发表于 2011-10-29 20:03:42 | 显示全部楼层
只能把它屏蔽掉,好听一点的办法是条件编译干掉它

出0入0汤圆

发表于 2011-10-29 20:23:52 | 显示全部楼层
条件编译就好了,这点在ucos上很常见,叫做可以剪裁

出0入0汤圆

发表于 2011-10-29 20:30:30 | 显示全部楼层
做成通用的函数,然后封装进库里,想用哪个调哪个。

出0入0汤圆

发表于 2013-4-9 20:04:46 | 显示全部楼层
条件编译方法挺好

出0入0汤圆

发表于 2013-4-9 20:27:01 | 显示全部楼层
条件编译+1

出70入0汤圆

发表于 2013-4-16 17:02:02 | 显示全部楼层
条件编译,加宏开关!

出0入0汤圆

发表于 2013-4-16 22:46:31 | 显示全部楼层
就像ASSERT一样

出0入0汤圆

发表于 2013-4-16 23:04:13 | 显示全部楼层
#if 0  #endif注释

出0入0汤圆

发表于 2013-4-16 23:06:06 来自手机 | 显示全部楼层
有优化选项的吧?

出0入0汤圆

发表于 2013-4-17 08:58:08 | 显示全部楼层
C/C++选项中ONE ELF……选项选上就可以了

出0入0汤圆

发表于 2013-4-19 14:58:15 | 显示全部楼层
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.

出50入0汤圆

发表于 2013-4-19 15:15:42 | 显示全部楼层
条件编译,正是

出0入0汤圆

发表于 2013-5-3 13:41:47 | 显示全部楼层
yj_yulin 发表于 2013-4-19 14:58
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将代码优化,还可以进一步节省程序空间:】

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2013-5-3 15:27:48 来自手机 | 显示全部楼层
学习一下....

出0入0汤圆

发表于 2013-5-3 17:29:55 | 显示全部楼层
感觉11楼的靠谱

出0入0汤圆

发表于 2013-5-3 17:47:34 | 显示全部楼层
不让编译进出就可以了,

出0入0汤圆

发表于 2013-5-3 18:22:53 | 显示全部楼层
反正我正在编写的一个工程中,现在还有很多还没有用上的函数,使用UNMOVEUNUSED后,体积就变小了,最重要的是没有那些烦人的警告。

出0入0汤圆

发表于 2014-1-10 23:14:13 | 显示全部楼层
16楼正解。只有通过这种方法告知编译器不要将未使用函数放入最终代码里。

出0入0汤圆

发表于 2014-1-11 00:58:21 | 显示全部楼层
讲的挺好的 有时间试试

出0入0汤圆

发表于 2014-1-11 12:40:45 | 显示全部楼层
好东西啊

出0入0汤圆

发表于 2014-1-11 13:24:05 | 显示全部楼层
本帖最后由 lswhome 于 2014-1-11 13:37 编辑

16楼的方法证实管用!!!同时谷歌浏览器的打印功能里直接就有另存为PDF的功能,非常方便哦,哇哈哈哈!!!!!

出0入13汤圆

发表于 2014-1-11 14:13:48 | 显示全部楼层
16楼的方法很好,学习下
另外条件编译也很一个很好的方法,在不动编程软件下最好的处理方式

出0入0汤圆

发表于 2014-1-12 16:22:50 | 显示全部楼层
16楼的办法不错   不过注释掉也可以哈

出0入0汤圆

发表于 2014-1-17 08:58:01 | 显示全部楼层
16楼的方法可行,但和直接去掉代码   仍有区别
代码会大几个字节

出0入0汤圆

发表于 2014-1-17 11:57:43 来自手机 | 显示全部楼层
十六楼的方式有空试一下

出0入0汤圆

发表于 2014-2-14 15:48:28 | 显示全部楼层
谢谢16L的办法

出0入0汤圆

发表于 2014-2-14 15:51:09 | 显示全部楼层
chencc8 发表于 2013-5-3 13:41
摘自http://bbs.zlgmcu.com/dispbbs.asp?boardid=43&ID=21190

Keil使用"REMOVEUNUSED"就可以简单实现:

+10086                  

出0入0汤圆

发表于 2014-2-14 16:17:04 | 显示全部楼层
终于在这里找到好办法,太棒了!

出0入0汤圆

发表于 2014-2-14 16:40:26 | 显示全部楼层
这办法不错,在产品上验证下看看

出0入0汤圆

发表于 2014-2-20 06:25:01 来自手机 | 显示全部楼层
标记,有空试一下

出0入0汤圆

发表于 2014-2-20 10:22:07 | 显示全部楼层
好方法啊!顶之!

出0入10汤圆

发表于 2014-2-21 17:03:45 | 显示全部楼层
顶16楼!这个方法好!我之前的方法也是将不用的函数注释掉!

出0入0汤圆

发表于 2014-2-25 23:54:32 来自手机 | 显示全部楼层
标记一下。

出70入145汤圆

发表于 2014-2-26 09:52:50 | 显示全部楼层
使用16楼的办法,为什么编译后出现const 和code 2个参数,没设置前只有code?

出0入0汤圆

发表于 2014-2-26 10:06:35 | 显示全部楼层
不得不顶16楼!
然来有这么方便的方法。

出0入0汤圆

发表于 2014-2-26 10:16:26 | 显示全部楼层
MARK,16喽方法

出0入0汤圆

发表于 2014-6-19 21:01:33 | 显示全部楼层
chencc8 发表于 2013-5-3 13:41
摘自http://bbs.zlgmcu.com/dispbbs.asp?boardid=43&ID=21190

Keil使用"REMOVEUNUSED"就可以简单实现:

学习了!~

出0入0汤圆

发表于 2014-6-19 21:09:58 | 显示全部楼层

MARK,16喽方法

出0入0汤圆

发表于 2014-6-19 21:43:13 | 显示全部楼层
标记一下,呵呵。

出0入0汤圆

发表于 2014-6-19 21:57:33 | 显示全部楼层
标记一下,有用

出0入0汤圆

发表于 2014-7-4 13:54:25 | 显示全部楼层
mark一记

出0入0汤圆

发表于 2014-7-4 15:04:02 | 显示全部楼层
16方法看着不错,下次试试

出0入0汤圆

发表于 2014-8-20 21:13:45 | 显示全部楼层
16楼的方法是可以减小,但是还是要多出好几百字节

出70入0汤圆

发表于 2014-8-20 21:27:02 | 显示全部楼层
你用的是旧版本KEIL2吧,KEIL3或4都会优化掉的,包括没调用过的函数、全局变量

出45入88汤圆

发表于 2017-11-16 11:35:41 | 显示全部楼层
gshuang1 发表于 2014-8-20 21:27
你用的是旧版本KEIL2吧,KEIL3或4都会优化掉的,包括没调用过的函数、全局变量 ...

我这里用16楼方法不行。会报L121错误

出10入120汤圆

发表于 2017-11-16 12:55:14 来自手机 | 显示全部楼层
Edesigner. 发表于 2017-11-16 11:35
我这里用16楼方法不行。会报L121错误

应该没有问题的,一直这么用,是不是没选择使用lx选项呢

出0入0汤圆

发表于 2017-11-16 16:43:17 | 显示全部楼层
keil 自动注释掉不使用代码     UNMOVEUNUSED

出0入0汤圆

发表于 2018-1-2 18:03:41 | 显示全部楼层


要选择 LX51

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-20 10:16

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表