Including a #define in all .c source files at compile time

前端 未结 3 1658
一整个雨季
一整个雨季 2020-12-19 02:33

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 wri

相关标签:
3条回答
  • 2020-12-19 03:04

    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

    0 讨论(0)
  • 2020-12-19 03:17

    gcc option -D:

    -D name
        Predefine name as a macro, with definition 1.
    
    -D name=definition
        ....
    

    so, in your case, gcc ... -Dmalloc=MYmalloc

    0 讨论(0)
  • 2020-12-19 03:19

    If you strive for redirecting malloc() calls to a custom function I would rather recommend to provide your custom code via pre-loading of your implementation at runtime. See this question for details.

    0 讨论(0)
提交回复
热议问题