我可以从具有许多编译器标志的c程序中导出使用的代码吗? [英] Can I export the used code from a c program with many compiler flags?

查看:54
本文介绍了我可以从具有许多编译器标志的c程序中导出使用的代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我们的linux驱动程序代码压缩为仅在当前内核上运行的代码.它的某些部分被if语句一直忽略到内核2.4.x

I would like to condense our linux driver code in to only the code that runs on the current kernel. It has parts that are ignored by if statements all the way back to kernele 2.4.x

您是否曾经听说过一种将代码编译为输出的方法,该输出将是工作代码,而如果else语句,则c编译器会忽略所有内容?

Have you ever heard of a way to compile the code to an output which will be the working code with out all the stuff ignored by the c compiler if else statements?

我想知道我们是否可以运行make或gcc来生成仅用于该构建的所有代码.

I am wondering if we can run make something or gcc something that will simply result in all the code that is used for that build.

就像我下面有这个.c文件一样,然后在运行make命令之后,我应该只有最新内核所需的代码.

So like if I had this .c file below, then after running the make command I should have just the code I need for the newest kernel.

example.c

example.c

static somefunction .... {
    avar = 0;
#if (linux_ver >= 2.6.31)
    some newer code
#elseif (linux_ver >= 2.4.24)
    some older code
#else
    original code
#endif

}

提取/压缩后,example.c的内容如下所示:

after extracting / condensing, example.c would simply read as below

static somefunction .... {
    avar = 0;
    some newer code
}

推荐答案

您需要使用的工具是 sunifdef 或(最新的) coan .

The tool you are after is sunifdef or (more recent) coan.

另请参阅:有C预处理程序可根据已定义或未定义的值消除#ifdef块吗?

这篇关于我可以从具有许多编译器标志的c程序中导出使用的代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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