Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to develop a loadable kernel module (LKM) on Linux with C++?

When I develop a loadable kernel module (LKM) should I use C?

Is it possible to develop a loadable kernel module (LKM) on Linux with language other than C for example C++?

like image 882
Amir Saniyan Avatar asked May 06 '12 08:05

Amir Saniyan


1 Answers

It may be possible to an extent, but be warned (from 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.

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.

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.

like image 58
CodeClown42 Avatar answered Sep 23 '22 15:09

CodeClown42