VPATH多路径搜索头文件的问题

初学内核编程,写了一个makefile文件,使用VPATH全局变量设置头文件搜索路径可还是显示找不到

makefile文件内容如下:

 ifneq ($(KERNELRELEASE),)
    obj-m += http.o
else
    PWD := $(shell pwd)
    KVER := $(shell uname -r)
    KDIR := /lib/modules/$(KVER)/build

VPATH = /usr/include:/usr/include/x86_64-linux-gnu:/usr/lib/gcc/x86_64-linux-gnu/4.8/include:/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed:/usr/local/include  
default:    
    $(MAKE) -C $(KDIR)  M=$(PWD) modules

all:
    make -C $(KDIR) M=$(PWD) modules 
clean:
    rm -rf *.o *.mod.c *.ko *.symvers *.order *.makers
 endif

代码如下:

 #include <linux/netfilter.h>  
#include <linux/init.h>  
#include <linux/module.h>  
#include <linux/netfilter_ipv4.h>  
#include <linux/ip.h>  
#include <linux/inet.h>  
#include <stdlib.h>
/** 
 * Hook function to be called. 
 * We modify the packet's src IP. 
 */  
unsigned int my_hookfn(const struct nf_hook_ops *ops,  
    struct sk_buff *skb,  
    const struct net_device *in,  
    const struct net_device *out,  
    int (*okfn)(struct sk_buff *))  
{  
    struct iphdr *iph;  
    iph = ip_hdr(skb);
    int * temp = iph;
    iph = realloc(iph,sizeof(iph)+4);
    printk(KERN_INFO"%lu\n",sizeof(*iph));
    return NF_ACCEPT;  
}  

/* A netfilter instance to use */  
static struct nf_hook_ops nfho = {  
    .hook = my_hookfn,  
    .pf = PF_INET,  
    .hooknum = NF_INET_PRE_ROUTING,  
    .priority = NF_IP_PRI_FIRST,  
    .owner = THIS_MODULE,  
};  

static int __init http_init(void)  
{  
    if (nf_register_hook(&nfho)) {  
        printk(KERN_ERR"nf_register_hook() failed\n");  
        return -1;  
    }  
    return 0;  
}  

static void __exit http_exit(void)  
{  
    nf_unregister_hook(&nfho);  
}  

module_init(http_init);  
module_exit(http_exit);  
MODULE_AUTHOR("flyking");  
MODULE_LICENSE("GPL"); 

错误提示如下:

 make -C /lib/modules/3.13.0-113-generic/build  M=/home/test/fk modules
make[1]: 正在进入目录 `/usr/src/linux-headers-3.13.0-113-generic'
  CC [M]  /home/test/fk/http.o
/home/test/fk/http.c:7:20: fatal error: stdlib.h: 没有那个文件或目录
 #include <stdlib.h>
                    ^
compilation terminated.
make[2]: *** [/home/test/fk/http.o] 错误 1
make[1]: *** [_module_/home/test/fk] 错误 2
make[1]:正在离开目录 `/usr/src/linux-headers-3.13.0-113-generic'
make: *** [default] 错误 2
## 

1个回答

gcc 添加-I$(VPATH)

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问