问题
I want to understand this error. Printing UID of a process, code:
printk(KERN_INFO "User ID = %d\n", (task)->cred->uid);
The error:
error: dereferencing pointer to incomplete type ‘const struct cred’
回答1:
It's pretty straightforward: the compiler is telling you that the type struct cred
is incomplete. In other words, the compiler does not know its definition, and therefore it does not know whether there is a uid
field or where in the struct the field is located. Therefore it cannot compile that ->uid
.
To fix this, simply include a correct definition of struct cred
:
#include <linux/cred.h>
来源:https://stackoverflow.com/questions/61211757/dereferencing-pointer-to-incomplete-type-const-struct-cred