yoko 发表于 2011-10-29 19:25:18

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

*** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
当程序中有未调用的函数时,KEIL 给出上述警告,
实际上这段函数也是占用程序空间的,函数中的变量也占用内存,而且当全局变量处理,KEIL 把未用调用的函数按中断函数方式处理。

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

i55x 发表于 2011-10-29 19:41:44

你说他占用空间,依据是什么?

yoko 发表于 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

xinfa190 发表于 2011-10-29 20:03:42

只能把它屏蔽掉,好听一点的办法是条件编译干掉它

tiancaigao7 发表于 2011-10-29 20:23:52

条件编译就好了,这点在ucos上很常见,叫做可以剪裁

surkenjur 发表于 2011-10-29 20:30:30

做成通用的函数,然后封装进库里,想用哪个调哪个。

clarkewayne 发表于 2013-4-9 20:04:46

条件编译方法挺好

t2397362 发表于 2013-4-9 20:27:01

条件编译+1

绿茶山人 发表于 2013-4-16 17:02:02

条件编译,加宏开关!

slfs007 发表于 2013-4-16 22:46:31

就像ASSERT一样

tragedy 发表于 2013-4-16 23:04:13

#if 0#endif注释

fshunj 发表于 2013-4-16 23:06:06

有优化选项的吧?

zhugean 发表于 2013-4-17 08:58:08

C/C++选项中ONE ELF……选项选上就可以了

yj_yulin 发表于 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.

261854681 发表于 2013-4-19 15:15:42

条件编译,正是

chencc8 发表于 2013-5-3 13:41:47

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将代码优化,还可以进一步节省程序空间:】

jz701209李 发表于 2013-5-3 15:27:48

学习一下....

zjk 发表于 2013-5-3 17:29:55

感觉11楼的靠谱

benqme 发表于 2013-5-3 17:47:34

不让编译进出就可以了,

chencc8 发表于 2013-5-3 18:22:53

反正我正在编写的一个工程中,现在还有很多还没有用上的函数,使用UNMOVEUNUSED后,体积就变小了,最重要的是没有那些烦人的警告。

derive3000 发表于 2014-1-10 23:14:13

16楼正解。只有通过这种方法告知编译器不要将未使用函数放入最终代码里。

dtdzlujian 发表于 2014-1-11 00:58:21

讲的挺好的 有时间试试

ypm 发表于 2014-1-11 12:40:45

好东西啊

lswhome 发表于 2014-1-11 13:24:05

本帖最后由 lswhome 于 2014-1-11 13:37 编辑

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

weiwei4 发表于 2014-1-11 14:13:48

16楼的方法很好,学习下
另外条件编译也很一个很好的方法,在不动编程软件下最好的处理方式

xou822 发表于 2014-1-12 16:22:50

16楼的办法不错   不过注释掉也可以哈

ordinary 发表于 2014-1-17 08:58:01

16楼的方法可行,但和直接去掉代码   仍有区别
代码会大几个字节

wzd5230 发表于 2014-1-17 11:57:43

十六楼的方式有空试一下

蓝海de梦 发表于 2014-2-14 15:48:28

{:biggrin:}谢谢16L的办法

flor 发表于 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                  

xiaobenyi 发表于 2014-2-14 16:17:04

终于在这里找到好办法,太棒了!

Let 发表于 2014-2-14 16:40:26

这办法不错,在产品上验证下看看

xCamel 发表于 2014-2-20 06:25:01

标记,有空试一下

macp 发表于 2014-2-20 10:22:07

好方法啊!顶之!

linbin250 发表于 2014-2-21 17:03:45

顶16楼!这个方法好!我之前的方法也是将不用的函数注释掉!

15813191501 发表于 2014-2-25 23:54:32

标记一下。

hailing 发表于 2014-2-26 09:52:50

使用16楼的办法,为什么编译后出现const 和code 2个参数,没设置前只有code?

LearningASM 发表于 2014-2-26 10:06:35

不得不顶16楼!
然来有这么方便的方法。

Honey_comb 发表于 2014-2-26 10:16:26

MARK,16喽方法

changshs 发表于 2014-6-19 21:01:33

chencc8 发表于 2013-5-3 13:41
摘自http://bbs.zlgmcu.com/dispbbs.asp?boardid=43&ID=21190

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


学习了!~

zqy517 发表于 2014-6-19 21:09:58


MARK,16喽方法

颜靖峰 发表于 2014-6-19 21:43:13

标记一下,呵呵。

pigy0754 发表于 2014-6-19 21:57:33

{:biggrin:}标记一下,有用

tzgok 发表于 2014-7-4 13:54:25

mark一记

iquer 发表于 2014-7-4 15:04:02

16方法看着不错,下次试试

cqfeiyu 发表于 2014-8-20 21:13:45

16楼的方法是可以减小,但是还是要多出好几百字节

gshuang1 发表于 2014-8-20 21:27:02

你用的是旧版本KEIL2吧,KEIL3或4都会优化掉的,包括没调用过的函数、全局变量

Edesigner. 发表于 2017-11-16 11:35:41

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

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

makesoft 发表于 2017-11-16 12:55:14

Edesigner. 发表于 2017-11-16 11:35
我这里用16楼方法不行。会报L121错误

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

snowdpq 发表于 2017-11-16 16:43:17

keil 自动注释掉不使用代码   UNMOVEUNUSED

TANK99 发表于 2018-1-2 18:03:41



要选择 LX51
页: [1]
查看完整版本: KEIL,未调用的函数怎么样才能不占程序空间