当我开发可加载内核模块 (LKM) 时,我应该使用 C 吗?
是否可以在 Linux 上使用非 C 语言(例如 C++)开发可加载内核模块 (LKM)?
最佳答案
这在一定程度上是可能的,但请注意(来自 http://www.tux.org/lkml/#s15-3):
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.
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++ 在那里工作。
但我非常怀疑这会很容易。您甚至无法访问内核中的完整 C 标准库。需要考虑的一点:它不链接到共享库,并且总可执行镜像通常为 2-3 MB。
关于c++ - 是否可以使用 C++ 在 Linux 上开发可加载内核模块(LKM)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10469188/