[英]How to specify path of kernel headers for non-kernel app in c?
I need to transfer fixp_t
typed number (defined at <linux/fixp-arith.h>
, originally s16
) from kernel module to client app using ioctl
. 我需要转移
fixp_t
键入号码(在限定<linux/fixp-arith.h>
最初s16
使用来自内核模块)到客户端应用程序ioctl
。 Data types are very important, if variable size will differ - results can be very dangerous. 如果变量大小不同,则数据类型非常重要-结果可能非常危险。
If i include <linux/fixp-arith.h>
in both kernel and client app source code, client app fails to compile, because it can't find linux headers. 如果我在内核和客户端应用程序源代码中都包含
<linux/fixp-arith.h>
,则客户端应用程序无法编译,因为它找不到Linux标头。
From other hand, gcc -I/usr/src/linux-headers-3.16.0-4-common/include/ app.c -o app
does not work, because <linux/types.h>
re-defines existing types and compilation fails. 另一方面,
gcc -I/usr/src/linux-headers-3.16.0-4-common/include/ app.c -o app
不起作用,因为<linux/types.h>
重新定义了现有类型并编译失败。
From other hand, i am scared to specify any data type by myself, because on every arch s16
, and so fixp_t
may be different. 从另一方面来说,我很害怕我自己指定任何数据类型,因为在每一个拱
s16
等fixp_t
可能会有所不同。
How is it possible to workaround this? 如何解决这个问题?
From the gcc man page: 从gcc手册页:
-I dir
Add the directory dir to the list of directories to be searched for header files.-I dir
将目录-I dir
添加到要搜索头文件的目录列表中。
So, to add the directory you would use: 因此,要添加目录,您将使用:
-I /usr/src/linux-headers-3.16.0-4-common/include/
However, I don't think user space programs are supposed to include kernel headers. 但是,我认为用户空间程序不应该包含内核头文件。 If your kernel module has a user space API, then that API should be declared in a header that is separate from the kernel headers and that relies only on standard header files.
如果您的内核模块具有用户空间API,则应在与内核头文件分开且仅依赖于标准头文件的头文件中声明该API。
Define your own ioctl
using what you want. 使用所需的内容定义自己的
ioctl
。
The specific header will be crafted so that can be included in both app and kernel. 特定的标头将经过精心设计,以便可以同时包含在应用程序和内核中。
Kernel modules, compiled against kernel headers, will do the correct conversion. 针对内核头文件编译的内核模块将执行正确的转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.