免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2870 | 回复: 6
打印 上一主题 下一主题

[C++] 如何改动makefile来避免没有改动过的.c文件重复编译 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-02-25 14:52 |只看该作者 |倒序浏览
本帖最后由 qfmeal 于 2016-02-25 14:55 编辑

我知道只有改动过源文件,make的时候才会重新编译。

我现在的情况是:
1.所有源文件没动过,时间戳没有变,任何操作都没有;
2.生成的中间文件和目标文件都在,没动过;
3.我的makefile是把不同目录生成的所有中间文件都移到同一个obj目录,最后在链接生成目标文件;
$(CUR_OBJ_CPP):%.o:%.cpp
        $(CC) $(CFLAGS) -c $^ -o $(OBJ_OUTPUT)/$@

但是每次 make的时候,所有的文件都会编译一遍,现在文件多了,每次编译很慢,所以想问下大牛们,这个问题怎么解决。

论坛徽章:
0
2 [报告]
发表于 2016-02-25 15:15 |只看该作者
那就用  make -j     多核编译

论坛徽章:
0
3 [报告]
发表于 2016-03-04 21:54 |只看该作者
检查系统时间

论坛徽章:
44
15-16赛季CBA联赛之浙江
日期:2021-10-11 02:03:59程序设计版块每日发帖之星
日期:2016-07-02 06:20:0015-16赛季CBA联赛之新疆
日期:2016-04-25 10:55:452016科比退役纪念章
日期:2016-04-23 00:51:2315-16赛季CBA联赛之山东
日期:2016-04-17 12:00:2815-16赛季CBA联赛之福建
日期:2016-04-12 15:21:2915-16赛季CBA联赛之辽宁
日期:2016-03-24 21:38:2715-16赛季CBA联赛之福建
日期:2016-03-18 12:13:4015-16赛季CBA联赛之佛山
日期:2016-02-05 00:55:2015-16赛季CBA联赛之佛山
日期:2016-02-04 21:11:3615-16赛季CBA联赛之天津
日期:2016-11-02 00:33:1215-16赛季CBA联赛之浙江
日期:2017-01-13 01:31:49
4 [报告]
发表于 2016-03-05 14:43 |只看该作者
回复 1# qfmeal

  1. $(CUR_OBJ_CPP):$(OBJ_OUTPUT)/%.o:%.cpp
  2.         $(CC) $(CFLAGS) -c $^ -o $@
复制代码

论坛徽章:
11
2015年迎新春徽章
日期:2015-03-04 09:55:282017金鸡报晓
日期:2017-02-08 10:39:4215-16赛季CBA联赛之辽宁
日期:2016-12-15 10:24:1715-16赛季CBA联赛之佛山
日期:2016-11-30 09:04:2015-16赛季CBA联赛之江苏
日期:2016-04-29 15:56:1215-16赛季CBA联赛之同曦
日期:2016-04-12 13:21:182016猴年福章徽章
日期:2016-02-18 15:30:3415-16赛季CBA联赛之山东
日期:2016-02-16 11:37:52每日论坛发贴之星
日期:2016-02-07 06:20:00程序设计版块每日发帖之星
日期:2016-02-07 06:20:0015-16赛季CBA联赛之新疆
日期:2018-01-09 16:25:37
5 [报告]
发表于 2016-03-11 12:09 |只看该作者
makefile太弱了,要用scons

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
6 [报告]
发表于 2016-03-11 13:27 |只看该作者
1. 写对target依赖

2. 用 ccache

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
7 [报告]
发表于 2016-03-11 13:38 |只看该作者
有一段时间 gcc 默认就是 ccache 的符号链接,刚看了一下 fedora 23 发现又变回去了. 需要自己设置一下

官网地址:
    https://ccache.samba.org/

Features

    Keeps statistics on hits/misses.
    Automatic cache size management.
    Can cache compilations that generate warnings.
    Easy installation.
    Low overhead.
    Optionally uses hard links where possible to avoid copies.

Limitations

    Only knows how to cache the compilation of a single C/C++/Objective-C/Objective-C++ file. Other types of compilations (multi-file compilation, linking, etc) will silently fall back to running the real compiler.
    Only works with GCC and compilers that behave similar enough.
    Some compiler flags are not supported. If such a flag is detected, ccache will silently fall back to running the real compiler.

Why bother?

If you ever run make clean; make, you can probably benefit from ccache. It is common for developers to do a clean build of a project for a whole host of reasons, and this throws away all the information from your previous compilations. By using ccache, recompilation goes much faster.

Another reason to use ccache is that the same cache is used for builds in different directories. If you have several versions or branches of a software stored in different directories, many of the object files in a build directory can probably be taken from the cache even if they were compiled for another version or branch.

A third scenario is using ccache to speed up clean builds performed by servers or build farms that regularly check that the code is buildable.

You can also share the cache between users, which can be very useful on shared compilation servers.


*Is it safe?*

Yes. The most important aspect of a compiler cache is to always produce exactly the same output that the real compiler would produce. This includes providing exactly the same object files and exactly the same compiler warnings that would be produced if you use the real compiler. The only way you should be able to tell that you are using ccache is the speed.

ccache has been coded very carefully to try to provide these guarantees. However, if you experience any bugs, please report them.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP