Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

c - Unable to include `linux/config.h` on 5.8 kernel

Originally I was trying to include linux/config.h to compile an old driver from source originated from the 2.6 kernel on the latest 5.8 kernel.

And here's the include part of this driver:

#include <linux/config.h>
#include <linux/module.h>
#include <linux/init.h>

#include <linux/kernel.h> /* printk() */
#include <linux/fs.h>     /* everything... */
#include <linux/types.h>  /* size_t */
#include <asm/uaccess.h>

And as per requested, I'm posting the Makefile here:

ifeq ($(KERNELRELEASE),)

    KERNELDIR ?= /lib/modules/$(shell uname -r)/build
    PWD := $(shell pwd)

modules:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

modules_install:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install

clean:
    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

.PHONY: modules modules_install clean

else
    obj-m := my_driver.o
endif

While I tried to compile this driver via gcc the compiler told me that linux/config.h could not been found.

I was told from the web to use linux/autoconf.h to replace linux/config.h but failed.

So I just wanna to know which file should I replace linux/config.h with to make this driver compiled and run.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The linux/config.h has not been needed since kernel 2.6.15. It was deprecated in kernel 2.6.15 and removed in kernel 2.6.19 (and also removed from some Red Hat 2.6.18 kernels). The following sequence may be used to conditionally include it:

#include <linux/version.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
#include <linux/config.h>
#endif

The main kernel Makefile uses GCC's -include file option to automatically define the kernel configuration option macros without the use of an explicit #include <linux/config.h> (or its replacements) in the C source files. There is no need to add #include <generated/autoconf.h> or similar to the C source files.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...