module compiling : asm/linkage.h file not found

后端 未结 5 1617
别跟我提以往
别跟我提以往 2021-01-01 19:18

I am trying to compile an example of \"hello world\" Kernel Module, problems found on ubuntu 11.04, kernel 3.2.6, gcc 4.5.2 and fedora 16, kernel 3.2.7, gcc 4.6.7.

c

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-01 19:46

    module compiling : asm/linkage.h file not found

    This means this particular file was not found in specified DIR, which gets specified when we use -I option with make.

    We can either link that asm-generic to asm, if all headers are present in asm-generic, or we can use make utility.

    Make utility is preferred in case of building kernel modules.

    Create a 'Makefile' in working DIR.

    obj-m += hello.o
    all:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    clean:
        make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    

    Use of -C option will change to DIR specified before reading the makefiles or doing anything else.

    So to avoid this error, use -C option with DIR/lib/modules/$(shell uname -r)/build

    By this your program will be able to find required files, you will get hello.ko file.

    You can add this to kernel modules by

    sudo insmod hello.ko
    

    Similarly you can remove by

    sudo rmmod hello
    

提交回复
热议问题