如何在kernel模块中使用已经编译好的obj文件
来源:互联网 发布:js向json对象添加元素 编辑:程序博客网 时间:2024/05/01 19:18
这也是一时心血来潮,觉得好玩。 在Document/kbuild/modules.txt中看到这么一段
Some external modules need to include an object file as a blob.
kbuild has support for this, but requires the blob file to be
named <filename>_shipped. When the kbuild rules kick in, a copy
of <filename>_shipped is created with _shipped stripped off,
giving us <filename>. This shortened filename can be used in
the assignment to the module.
Throughout this section, 8123_bin.o_shipped has been used to
build the kernel module 8123.ko; it has been included as
8123_bin.o.
8123-y := 8123_if.o 8123_pci.o 8123_bin.o
Although there is no distinction between the ordinary source
files and the binary file, kbuild will pick up different rules
when creating the object file for the module.
想着好玩,就自己试了一下,开始不成功,后来在高手的帮助下终于成功了。
1。 创建自己的obj文件
我最开始使用 gcc -c ex_obj.c -o ex_obj.o_shipped 来做的,结果链接后不能正常工作。
原来是一定要放在编译kernel的环境中编译这个obj。网上高手说了 要这么写
ifneq ($(KERNELRELEASE),)
obj-y := xxxx.o #your obj files goes here. 关键在这里,用obj-y 来指定要编译的,然后这个过程就在编译的时候停了,不会继续链接。
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD)
endif
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
depend .depend dep:
$(CC) $(CFLAGS) -M *.c > .depend
ifeq (.depend,$(wildcard .depend))
include .depend
endif
编译成功后,将这个拷贝到需要链接的模块目录。
记住要添加_shipped后缀
2。 然后在需要这个obj的模块中添加
scull-y := main.o pipe.o access.o ex_obj.o
然后在源代码中调用相应的函数,ok,可以了。
不过貌似没有啥实际用处。 :)
- 如何在kernel模块中使用已经编译好的obj文件
- lein中如何使用已经编译好的class文件
- .Net,Dll扫盲篇,如何在VS中调试已经编译好的dll?
- 1>main.cu.obj : error LNK2005: _main 已经在 kernel.cu.obj 中定义
- 错误2error LNK2005: *已经在 *.obj 中定义(使用多个.cpp文件时,应注意的事项)
- 如何在android模拟器中安装并运行已经开发好的或者别人写好的apk文件
- 如何在android模拟器中安装并运行已经开发好的或者别人写好的apk文件
- 如何在android模拟器中安装并运行已经开发好的或者别人写好的apk文件 .
- LINK 2005错误。*** 已经在*.obj文件中定义
- error LNK2005: 已经在 .obj 中定义 :用单独的.h文件包含全局变量
- C++中“已经在 test.obj 中定义”的错误
- 把ssl模块加入到已经编译好的apache中
- 把ssl模块加入到已经编译好的apache中
- 把ssl模块加入到已经编译好的apache中实现HTTPS
- 如何将一个已经编译好的so文件编译进system/lib64目录下
- 关于“已经在***.obj中定义”的问题
- error LNK2005 已经在***.obj中定义 的解决办法
- 已经编译好的64位GCC,如何在Redhat上运行
- spring数据源的注入、JdbcTemplate管理、编程式的事务管理DataSourceTransactionManager
- 实现opengl 中gluLookAt函数
- COM的优点
- C#汉字转拼音首字母
- Android 程序之在线词典
- 如何在kernel模块中使用已经编译好的obj文件
- linux等待队列
- C# 后台异步处理进程
- 健康减肥
- cute functions
- js和C#中的字符串编码解码
- RVDS4.0 破解
- Asp.net_获取GridView行号
- Ext form action 提交返回方式