linux - Print messages in kernel module using c++ -


I am editing a kernel module written in C ++ I want a function to print a message, but I think I can not use the cout or any standard input / output stream library function because the module stays in the kernel space.

I have tried to include iostream library:

  .... #include   

When I compile with G ++ :

  Error: iostream: Any such file Or directory is not error: 'Cout' was not declared in this area    

The Linux kernel does not support C ++ very well, and you can & lt; Iostream & gt; - I suspect that none of the STLs are completely out of the question, but since I have seen in C ++ Linux kernel mode

The standard implementation of cout and cerr are using OS features, which will definitely not work inside the kernel. So you should not use them, it would be possible to implement anything that works the same way (call it kostream ), and kostream & amp; Operator & lt; & Lt; (Kostream & os, sometype value) , which produces some output in the buffer, then use printk or some preferences that are printk To produce the actual output

Whether it is C or C ++, you can finally print printk (or its components) to print things in the Linux kernel. Parts) can be used.

Note that the use of fstream or stringstream is not also working inside the kernel.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -