如何覆盖在fprintf中的C库?如何添加GCC选项的顶层的CMakeLists.txt? [英] How to override fprintf in the C library? How to add GCC option to toplevel CMakeLists.txt?
问题描述
我知道如何重写只是简单的样品中C-lib中的功能。但是,我需要的是在具有数百个调用fprintf文件的一个真实的项目。
I know how to overwrite C-lib functions in just simple sample. But what I need is IN A REAL PROJECT which has hundreds of files that call fprintf.
在每个文件中,有一个#包括<文件stdio.h>中
,以及数十或数百的调用fprintf中
。我要让所有这些fprintf中做我自己的工作。我不能删除stdio.h中
,把一个#&包括LT; myprint.h>中
,其中, myprint.h
fprintf中定义的真正功能或的宏,做我自己的工作。
stdio.h中
拥有该项目的许多其它呼叫。我想要一个简单的解决方案,足以
In each file, there's a "#include < stdio.h >"
, and tens or hundreds of calls of fprintf
. I wanna make all these fprintf to do my own job. I cannot remove the "stdio.h"
and put a "#include < myprint.h >"
, where myprint.h
defines the real function or macro of fprintf
that do my own job. "stdio.h"
has many other calls in the project. I want a simple enough solution.
谢谢!
让我的问题不够清楚?...
Do I make my question clear enough?...
在2014年3月8日更新:
礼炮所有女性在第一次...
Update on 2014.03.08: Salute to all women at first...
请看看我下面的第二个帖子。
Please see my 2nd post below.
推荐答案
如果您使用的是例如GCC,您可以通过以下方式调用它:
If you are using gcc for example, you can invoke it in the following way:
gcc -include myheader.h -Dfprintf=myfprintf file.c
这将包括 myheader.h
前,每隔一包括 file.c中
头和将重新定义 fprintf中
为 myfprintf
。
And that will include myheader.h
before every other include header in file.c
and will redefine fprintf
as myfprintf
.
您可以找到更多的细节这里
You can find more details here
这篇关于如何覆盖在fprintf中的C库?如何添加GCC选项的顶层的CMakeLists.txt?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!