Linux内核版本宏定义 [英] Linux Kernel Version Macro Definition
问题描述
我不知道是否有一个GCC宏,会告诉我的Linux内核版本,所以我可以适当地设置变量类型。如果没有,我怎么会去定义我自己的宏,这是否?
I'm wondering if there is a gcc macro that will tell me the Linux kernel version so I can set variable types appropriately. If not, how would I go about defining my own macro that does this?
推荐答案
在的linux / version.h中文件中有一个名为宏 KERNEL_VERSION
这将让你检查你想要的版本,针对当前的Linux版本的头( LINUX_VERSION_ code
)安装。例如,要检查当前Linux头对内核的 v2.6.16 的或更早版本:
The linux/version.h file has a macro called KERNEL_VERSION
which will let you check the version you want against the current linux headers version (LINUX_VERSION_CODE
) installed. For example to check if the current Linux headers are for kernel v2.6.16 or earlier:
#include <linux/version.h>
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,16)
...
#else
...
#endif
有一个更好的方式来获得在运行时的版本信息是使用的utsname
功能<一个href=\"http://lxr.free-electrons.com/source/include/linux/utsname.h#L71\">include/linux/utsname.h.
A better way to get the version information at run-time is to use the utsname
function in include/linux/utsname.h.
char *my_kernel_version = utsname()->release;
这实质上是如何的/ proc /版本
获取当前内核verison。
This is essentially how /proc/version
gets the current kernel verison.
这篇关于Linux内核版本宏定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!