MODPOST 1 modules/bin/sh: scripts/mod/modpost: not found的解决

本文介绍如何在Linux 2.6环境下编译一个简单的hello.ko驱动模块,包括下载内核源码、配置内核、编写测试程序及配置Makefile等步骤,并提供了避免警告信息的方法。
AI助手已提取文章相关产品:

linux 2.6下编译最简单的hello.ko驱动

1.下载kernel源码 http://www.kernel.org/
2.配置内核
luther@gliethttp:~/work/kernel/linux-2.6.22.14$ make oldconfig
luther@gliethttp:~/work/kernel/linux-2.6.22.14$ make prepare
luther@gliethttp:~/work/kernel/linux-2.6.22.14$ make scripts 否则提示:MODPOST 1 modules/bin/sh:scripts/mod/modpost:notfound
3.写测试程序hello.c
//luther
@gliethttp:~/work/kernel/module_drivers/hello$ vim hello.c
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>

staticintinit_hello_4(void)
{
printk(KERN_ALERT"Hello, world 4 ");
return0;
}

staticvoidcleanup_hello_4(void)
{
printk(KERN_ALERT"Goodbye, world 4 ");
}

module_init(init_hello_4);
module_exit(cleanup_hello_4);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Playmud");
MODULE_DESCRIPTION("Test only!");
4.配置Makefile和执行ko编译
luther@gliethttp:~/work/kernel/module_drivers/hello$ echo"obj-m:=hello.o">Makefile
luther@gliethttp:~/work/kernel/module_drivers/hello$ make-C/usr/src/`uname-r` M=`pwd` modules
我下载的内核位置为~/work/kernel/linux-2.6.22.14,所以这里指定为:
luther@gliethttp:~/work/kernel/module_drivers/hello$ make-C../../linux-2.6.22.14 M=`pwd` modules
make:Entering directory `/home/
luther/work/kernel/linux-2.6.22.14'

WARNING: Symbol version dump /home/luther
/work/kernel/linux-2.6.22.14/Module.symvers
is missing; modules will have no dependencies and modversions.

Building modules, stage 2.
MODPOST 1 modules
CC /home/luther/work/kernel/module_drivers/hello/hello.mod.o
LD [M] /home/luther/work/kernel/module_drivers/hello/hello.ko
make: Leaving directory `/home/luther/work/kernel/linux-2.6.22.14'

luther@gliethttp:~/work/kernel/module_drivers/hello$



上面的做法当然是可以,但是老是提示:
WARNING: Symbol version dump /home/luhter/work/kernel/linux-2.6.22.14/Module.symvers is missing; modules will have no dependencies and modversions.

通过摸索,原来,编译hello.ko其实是非常简单的,不用下载kernel源码,
写测试程序hello.c
//luther@gliethttp:~/work/kernel/module_drivers/hello$ vim hello.c
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>

staticintinit_hello_4(void)
{
printk(KERN_ALERT"Hello, world 4 ");
return0;
}

staticvoidcleanup_hello_4(void)
{
printk(KERN_ALERT"Goodbye, world 4 ");
}

module_init(init_hello_4);
module_exit(cleanup_hello_4);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Playmud");
MODULE_DESCRIPTION("Test only!");
4.配置Makefile和执行ko编译
luther @gliethttp:~/work/kernel/module_drivers/hello$ echo"obj-m:=hello.o">Makefile
luther @gliethttp:~/work/kernel/module_drivers/hello$ make -C /lib/modules/`uname -r`/build M=`pwd` modules
make: Entering directory `/usr/src/linux-headers-2.6.22-14-generic'
CC [M] /home/
luther /work/kernel/module_drivers/hello/hello.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/
luther /work/kernel/module_drivers/hello/hello.mod.o
LD [M] /home/
luther /work/kernel/module_drivers/hello/hello.ko
make: Leaving directory `/usr/src/linux-headers-2.6.22-14-generic'
luther @gliethttp:~/work/kernel/module_drivers/hello$

/lib/modules/`uname -r`/build就是本地ubuntu机子的module编译配置目录

不是为正在运行的内核编译模块:
make -C <path-to-kernel> M='pwd'
为正在运行的内核编译模块:
make -C /lib/modules/'uname -r'/build M='pwd'

不用下载kernel,直接就在本地机搞定了!

printk没有在console上打印出提示,通过
luther @gliethttp:~/work/kernel/module_drivers/hello$ dmesg |tail
可以查到,具体配置可以查看
luther @gliethttp:~/work/kernel/module_drivers/hello$ vim /etc/syslog.conf

您可能感兴趣的与本文相关内容

.168/.configured' failed make[4]: [/home/x/nm/platform/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/linux-nvt9853x_generic/linux-5.10.168/.configured] Error 1 (ignored) if [ -e /home/x/nm/platform/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/mcu ]; then rm -rf /home/x/nm/platform/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/mcu/.prepared*; fi touch /home/x/nm/platform/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/linux-nvt9853x_generic/linux-5.10.168/.configured rm -f /home/x/nm/platform/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/linux-nvt9853x_generic/linux-5.10.168/vmlinux /home/x/nm/platform/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/linux-nvt9853x_generic/linux-5.10.168/System.map source env_setup.sh /home/x/nm/platform/nvmp/../sdk/soc/nvt9853x/glibc-toolchain-10.4.0/ && make -C /home/x/nm/platform/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/linux-nvt9853x_generic/linux-5.10.168 ARCH=arm64 CROSS_COMPILE=aarch64-ca53-linux-gnu- CC=aarch64-ca53-linux-gnu-gcc uImage.lzma -j6 make[5]: Entering directory '/home/x/nm/platform/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/linux-nvt9853x_generic/linux-5.10.168' SYNC include/config/auto.conf.cmd UPD include/generated/nvtversion.h HOSTCC scripts/sorttable HOSTCC scripts/mod/mk_elfconfig MKELF scripts/mod/elfconfig.h HOSTCC scripts/mod/sumversion.o HOSTCC scripts/mod/file2alias.o HOSTCC scripts/mod/modpost.o HOSTLD scripts/mod/modpost CALL scripts/atomic/check-atomics.sh CALL scripts/checksyscalls.sh CHK include/generated/compile.h CC drivers/soc/nvt/basic/nvt-info.o AR drivers/soc/nvt/basic/built-in.a AR drivers/soc/nvt/built-in.a AR drivers/soc/built-in.a AR drivers/built-in.a GEN .version CHK include/generated/compile.h UPD include/generated/compile.h CC init/version.o AR init/built-in.a LD vmlinux.o MODPOST vmlinux.symvers WARNING: modpost: "slpClass" [vmlinux] is a static EXPORT_SYMBOL MODINFO modules.builtin.modinfo GEN modules.builtin LD .tmp_vmlinux.kallsyms1 KSYMS .tmp_vmlinux.kallsyms1.S AS .tmp_vmlinux.kallsyms1.S LD .tmp_vmlinux.kallsyms2 KSYMS .tmp_vmlinux.kallsyms2.S AS .tmp_vmlinux.kallsyms2.S LD vmlinux SORTTAB vmlinux SYSMAP System.map OBJCOPY arch/arm64/boot/Image LZMA arch/arm64/boot/Image.lzma UIMAGE arch/arm64/boot/uImage.lzma /home/x/nm/platform/nvmp/staging_dir/host/bin/mkimage: /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1: version `OPENSSL_1_1_1' not found (required by /home/x/nm/platform/nvmp/staging_dir/host/bin/mkimage) arch/arm64/boot/Makefile:67: recipe for target 'arch/arm64/boot/uImage.lzma' failed make[6]: *** [arch/arm64/boot/uImage.lzma] Error 1 arch/arm64/Makefile:169: recipe for target 'uImage.lzma' failed make[5]: *** [uImage.lzma] Error 2 make[5]: Leaving directory '/home/x/nm/platform/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/linux-nvt9853x_generic/linux-5.10.168' Makefile:81: recipe for target '/home/x/nm/platform/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/linux-nvt9853x_generic/linux-5.10.168/.modules' failed make[4]: *** [/home/x/nm/platform/nvmp/build_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/linux-nvt9853x_generic/linux-5.10.168/.modules] Error 2 make[4]: Leaving directory '/home/x/nm/platform/nvmp/target/linux/nvt9853x' Makefile:13: recipe for target 'compile' failed make[3]: *** [compile] Error 2 make[3]: Leaving directory '/home/x/nm/platform/nvmp/target/linux' target/Makefile:21: recipe for target 'target/linux/compile' failed make[2]: *** [target/linux/compile] Error 2 make[2]: Leaving directory '/home/x/nm/platform/nvmp' target/Makefile:16: recipe for target '/home/x/nm/platform/nvmp/staging_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/stamp/.target_compile' failed make[1]: *** [/home/x/nm/platform/nvmp/staging_dir/target-aarch64-ca53-linux-gnueabihf-s385dpsv1/stamp/.target_compile] Error 2 make[1]: Leaving directory '/home/x/nm/platform/nvmp' /home/x/nm/platform/nvmp/include/toplevel.mk:203: recipe for target 'world' failed make: *** [world] Error 2
09-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值