我怎么能编译,而不改变其源编辑过程中的可执行文件? [英] How can I edit an executable during compiling, without changing its source?

查看:162
本文介绍了我怎么能编译,而不改变其源编辑过程中的可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须写一个Makefile其编译文件year.c,并在此之后,它会显示当前年份(2014年),而不是previous一(2013年)。我曾与SED功能尝试,但它仅如果我使用make运行。

 的#include<&stdio.h中GT;的#ifndef YEAR
 #定义YEAR2013
#万一诠释主(){
  的printf(你好世界,从年\\ n);
  返回0;
}

和Makefile文件:

 年:year.c
        GCC year.c -o年跑:
        ./year | SED -e'S / 3/4 / G'
清洁:
        RM年的Makefile


解决方案

只要定义在命令行上 - 在的#ifndef 将确保它不会重新定义:

  GCC -DYEAR = \\2014 \\-o年year.c

I have to write a Makefile which compile the file year.c , and after this it will show the current year(2014) , not the previous one(2013).I have tried with sed function , but it works only if i use make run .

#include <stdio.h>

#ifndef YEAR
 #define YEAR "2013"
#endif

int main(){
  printf("Hello world from " YEAR "\n");
  return 0;
}

And the Makefile:

year: year.c
        gcc year.c -o year

run:
        ./year | sed -e 's/3/4/g'
clean:
        rm year Makefile

解决方案

Just define YEAR on the command line - the #ifndef will make sure that it doesn't get redefined:

gcc -DYEAR=\"2014\" -o year year.c 

这篇关于我怎么能编译,而不改变其源编辑过程中的可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆