可以使用C ++在Linux上开发可加载内核模块(LKM)吗? [英] Is it possible to develop a loadable kernel module (LKM) on Linux with C++?
问题描述
当我开发可加载内核模块(LKM)时,我应该使用C吗?
When I develop a loadable kernel module (LKM) should I use C?
是否可以在Linux上使用非C语言(例如C ++)开发可加载内核模块(LKM)?
Is it possible to develop a loadable kernel module (LKM) on Linux with language other than C for example C++?
推荐答案
It may be possible to an extent, but be warned (from http://www.tux.org/lkml/#s15-3):
用C ++编写新驱动程序是一个好主意吗? 简短的答案是 不,因为内核中不支持C ++驱动程序.
Is it a good idea to write a new driver in C++? The short answer is no, because there isn't any support for C++ drivers in the kernel.
为什么不向内核添加C ++接口层以支持C ++驱动程序? 简短的答案是为什么要打扰,因为没有任何C ++驱动程序用于 Linux.
Why not add a C++ interface layer to the kernel to support C++ drivers? The short answer is why bother, since there aren't any C++ drivers for Linux.
我认为最好的主意是查阅所有使用C语言编写的现有资源(有一些内核驱动程序书籍,其中包括免费的在线书籍),弄清楚基础知识,然后您可以尝试看看是否可以获取C ++在那里工作.
I think the best idea is to consult existing resources (there are a few kernel driver books, including a free one online) which are all in C, get the basics figured out, then you can try and see if you can get c++ to work there.
但是我非常怀疑这会很容易.您甚至没有访问内核中完整的C标准库的权限.需要考虑的一点:它不链接到共享库,并且可执行映像的总大小通常为2-3 MB.
But I very much doubt that will be easy. You don't even have access to the full C standard library in the kernel. Something to think about: it does not link to shared libraries, and the total executable image is usually 2-3 MB.
这篇关于可以使用C ++在Linux上开发可加载内核模块(LKM)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!