增量编译时间很长

Technical Note

Architectures:

All

Component:

compiler

Updated:

2023/7/31 9:10

问题

在开发大型项目(比如AUTOSAR)时,用户更新对应的源代码然后编译时,编译器默认会执行增量编译:只需要重新编译更新的源代码,这样可以大大降低编译的时间。但是用户发现有时只更新很少源代码,编译也需要很长的时间:

原因

默认情况下,编译器是单独编译每个源文件,然后再Link生成最后的可执行文件。当用户只更新很少源代码编译时,编译器会执行增量编译:只重新编译更新的源代码,这样可以大大降低编译的时间。

但是如果用户使能了“Multi-file Compilation”,编译的时候会同时编译所有的源代码,这样即使只更新很少源代码,增量编译也会重新编译所有的源代码,如果源代码比较多(比如AUTOSAR),增量编译的时间跟重新编译的时间差不多,都会很长。

解决方法

如果没有特别的需求,一般不要使能“Multi-file Compilation”。

 

PS: 下面说明如何来检查是否使能了 “Multi-file Compilation” :

1. 工程左边的“Multi-file Compilation”标识:

2. Build Log: 如果源文件有很多,但是编译之后Build窗口只显示一个.c文件,说明使能了 “Multi-file Compilation”:

3. Build Log: (需要使能All)编译选项里面有-mfc(multi-file compilation),说明使能了“Multi-file Compilation”:

4. 检查.ewp文件里面的工程配置: 如果有-mfc(multi-file compilation)配置,说明使能了“Multi-file Compilation”:

参考文献:

  1. IAR Embedded Workbench IAR C/C++ Development Guide(multi-file compilation)

We do no longer support Internet Explorer. To get the best experience of iar.com, we recommend upgrading to a modern browser such as Chrome or Edge.