linux - 如何在Linux gcc编译器中编译<linnux/kernel.h>?

标签 linux gcc linux-kernel

我有一个简单的问题。我想编译以下c文件:

#include <linux/kernel.h>
#include <linux/module.h>
#include <sys/syscall.h>

extern void *sys_call_table[];


asmlinkage int (*original_sys_open)(int);

asmlinkage int our_fake_open_function(int error_code)
{

        /*print message on console every time we
 *          *are called*/
        printk("HEY! sys_open called with error_code=%d\n",error_code);

        /*call the original sys_exit*/
        return original_sys_open(error_code);
}

/*this function is called when the module is
*  *loaded (initialization)*/
int init_module()
{
        /*store reference to the original sys_exit*/
        original_sys_open=sys_call_table[__NR_open];

        /*manipulate sys_call_table to call our
 *          *fake exit function instead
 *                   *of sys_exit*/
        sys_call_table[__NR_open]=our_fake_open_function;
}


/*this function is called when the module is
 *  *unloaded*/
void cleanup_module()
{

        /*make __NR_exit point to the original
 *          *sys_exit when our module
 *                   *is unloaded*/
        sys_call_table[__NR_open]=original_sys_open;

}

问题是 gcc -I/usr/src/kernels/2.6.32-279.el6.x86_64/include myfile.c 生成一个无法解决的包含依赖项,可以在 . 请告诉我如何解决我今天遇到的 gcc 编译器问题。非常感谢您的见解。

最佳答案

如何构建外部模块记录在the documentation中:

$ make -C <path_to_kernel_src> M=$PWD

关于linux - 如何在Linux gcc编译器中编译<linnux/kernel.h>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19523971/

相关文章:

c++ - 根据鼠标和键盘交互检测计算机是否空闲

C程序编译ASM文件的命令

c++ - 如何使用 gcc 模仿 Microsoft 版本的 __FUNCTION__?

无法使用 gcc 编译 ANSI C 代码

memory-management - Linux 内核中处理 TLB 未命中的调用图

linux - Linux 中的 log4j xml 配置

linux - 报告中未显示象形文字语言 - 祖鲁语

c - 整数加法中多余的中间存储指令

linux - rw_semaphore 阻塞 I/O 重线程

networking - 为什么在ifconfig下不抓包?