包括在编译的时候在所有的.c源文件的#define [英] Including a #define in all .c source files at compile time

查看:236
本文介绍了包括在编译的时候在所有的.c源文件的#define的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在大约300 .c文件顶部包括的#define 。我想preFER不改变code作为它是开源的code,但如果我有,我会只写一个脚本来修改的所有文件。有没有使用gcc添加方式的#define 或头文件包括编译过程中每一个源文件的顶部?在的#define 是这样的:

 #定义的malloc MYmalloc


解决方案

您可以通过 -Dmalloc = MYmalloc GCC 选项。

有关 -D 选项的详细信息:

<一个href=\"http://gcc.gnu.org/onlinedocs/gcc/$p$pprocessor-Options.html\">http://gcc.gnu.org/onlinedocs/gcc/$p$pprocessor-Options.html

请注意,如果要修改的malloc 函数的行为出于调试的目的,你也可能有兴趣在的glibc 的malloc 挂钩:

<一个href=\"http://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html\">http://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html

I need to include a #define at the top of around 300 .c files. I would prefer not to change the code as it is open source code but if I have to I will just write a script to modify all the files. Is there a way using gcc to add a #define or header file include to the top of every source file during compilation? The #define is this:

#define malloc MYmalloc

解决方案

You can pass -Dmalloc=MYmalloc to the gcc options.

For more information about the -D option:

http://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html

Note that if you want to modify the behavior of malloc function for debugging purposes, you may also be interested in glibc malloc hooks:

http://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html

这篇关于包括在编译的时候在所有的.c源文件的#define的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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