linux 模块编译
2016-07-05 11:44
423 查看
模板编写一个简单的Makefile,如下所示:
obj-m := hello.o
并使用如下命令编译Hello World模块,如下所示:
make -C /usr/src/linux-2.6.15.5/ M=/driver_study/ modules
如果当前处于模块所在的目录,则以下命令与上述命令同等:
make –C /usr/src/linux-2.6.15.5 M=$(pwd) modules
其中-C后指定的是Linux内核源代码的目录,而M=后指定的是hello.c和Makefile所在的目录,编译结果如下所示:
[root@localhost driver_study]# make -C /usr/src/linux-2.6.15.5/
M=/driver_study/ modules
make: Entering directory '/usr/src/linux-2.6.15.5'
CC [M] /driver_study/hello.o
/driver_study/hello.c:18:35: warning: no newline at end of file
Building modules, stage 2.
MODPOST
CC /driver_study/hello.mod.o
LD [M] /driver_study/hello.ko
make: Leaving directory '/usr/src/linux-2.6.15.5'
从中可以看出,编译过程中经历了这样的步骤:先进入Linux 内核所在的目录,并编译出hello.o 文件,运行MODPOST 会生成临时的hello.mod.c 文件,而后根据此文件编译出 hello.mod.o,之后连接hello.o 和hello.mod.o 文件得到模块目标文件hello.ko,最后离开Linux内核所在的目录。
obj-m := hello.o
并使用如下命令编译Hello World模块,如下所示:
make -C /usr/src/linux-2.6.15.5/ M=/driver_study/ modules
如果当前处于模块所在的目录,则以下命令与上述命令同等:
make –C /usr/src/linux-2.6.15.5 M=$(pwd) modules
其中-C后指定的是Linux内核源代码的目录,而M=后指定的是hello.c和Makefile所在的目录,编译结果如下所示:
[root@localhost driver_study]# make -C /usr/src/linux-2.6.15.5/
M=/driver_study/ modules
make: Entering directory '/usr/src/linux-2.6.15.5'
CC [M] /driver_study/hello.o
/driver_study/hello.c:18:35: warning: no newline at end of file
Building modules, stage 2.
MODPOST
CC /driver_study/hello.mod.o
LD [M] /driver_study/hello.ko
make: Leaving directory '/usr/src/linux-2.6.15.5'
从中可以看出,编译过程中经历了这样的步骤:先进入Linux 内核所在的目录,并编译出hello.o 文件,运行MODPOST 会生成临时的hello.mod.c 文件,而后根据此文件编译出 hello.mod.o,之后连接hello.o 和hello.mod.o 文件得到模块目标文件hello.ko,最后离开Linux内核所在的目录。
相关文章推荐
- windows、linux、mac系统Charles破解注册安装和使用说明
- Linux文件系统简介
- linux 技巧:使用 screen 管理你的远程会话
- Linux 文件权限
- Linux中安装SSL协议依赖库OpenSSL的教程
- Linux rsync+inotify实现实时同步
- APUE linux下 sys/ioctl.h 作用
- Linux-VMware安装使用
- CentOS7配置samba4.2到Win8
- linux find 命令详解
- linux java 线上问题排查
- linux 重命名 rename
- ARM Linux 3.x 的设备树(Device Tree)之DTB、DTS
- linux系统数据盘挂载教程
- Linux中的wget网络下载命令使用全解
- linux串口termios(转载)
- Linux系统及应用问题分析排查工具
- Consul 多数据中心配置 MULTIPLE DATACENTERS
- linux命令 more
- Linux下远程桌面Windows