Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C内核模块程序交叉编译错误_C_Compiler Errors_Compilation_Embedded Linux - Fatal编程技术网

C内核模块程序交叉编译错误

C内核模块程序交叉编译错误,c,compiler-errors,compilation,embedded-linux,C,Compiler Errors,Compilation,Embedded Linux,我已经开发了一个linux内核模块,我想将它插入到我的内核中。 但是,当我试图交叉编译它时,会发生许多我没有解决的错误 这是模块代码: #include <linux/init.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/device.h> #include <linux/kernel.h> #include <linux/uaccess

我已经开发了一个linux内核模块,我想将它插入到我的内核中。 但是,当我试图交叉编译它时,会发生许多我没有解决的错误

这是模块代码:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/device.h>  
#include <linux/kernel.h>
#include <linux/uaccess.h>
#include <linux/input.h>



MODULE_LICENSE("GPL");      
MODULE_AUTHOR("Gaston");  
MODULE_DESCRIPTION("A simple Linux char driver"); 
MODULE_VERSION("0.1"); 

#define BTN_FILE_PATH "/dev/input/event0"
#define MAX 256

static char message[MAX] =""; 


int file;
size_t  rb;
int yalv;
struct input_event  ev[64];
char *str = BTN_FILE_PATH;



ssize_t exer_open(struct inode *pinode, struct file *pfile) {

    printk(KERN_INFO "Device has been opened\n");

    if((file = exer_open(str, O_RDONLY)) < 0) {
        printk("simplekey: File can not open");
        return(-1);
    }

    return 0;
}



ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {

    rb= exer_read(file, &ev, sizeof(ev));

        if (rb < (int) sizeof(struct input_event)) {
            printk("simplekey: short read");
            return(-1);
        }

        for (yalv = 0;
            yalv < (int) (rb / sizeof(struct input_event));
            yalv++) {
            if (ev[yalv].type == EV_KEY) {

                /* Change state on button pressed */
                if (ev[yalv].value == 0)
                    eval_keycode(ev[yalv].code);
            }
        }

    return 0;
}


ssize_t exer_write(struct file *pfile, const char __user *buffer, size_t length, loff_t *offset) {
    if (length > MAX)
        return -EINVAL;

    if (copy_from_user(message, buffer, length) != 0)
        return -EFAULT;

    printk(KERN_INFO "Received %s characters from the user\n", message);
    return 0;

}   


ssize_t exer_close(struct inode *pinode, struct file *pfile) {

    exer_close(file);
    printk(KERN_INFO "Device successfully closed\n");
    return 0;
}


struct file_operations exer_file_operations = { 
    .owner = THIS_MODULE,
    .open = exer_open,
    .read = exer_read,
    .write = exer_write,
    .release = exer_close,
};


int exer_simple_module_init(void) {

    printk(KERN_INFO "Initializing the LKM\n");
    register_chrdev(240, "Simple Char Drv", &exer_file_operations);
    return 0;
}


void exer_simple_module_exit(void) {

    unregister_chrdev(240, "Simple Char Drv");
}

module_init(exer_simple_module_init);
module_exit(exer_simple_module_exit);
这是我运行Make编译时遇到的错误:

/home/gaston/ledshared/exer_simple_char_drv.c: In function ‘exer_open’:
/home/gaston/ledshared/exer_simple_char_drv.c:34:23: error: passing argument 1 of ‘exer_open’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  if((file = exer_open(str, O_RDONLY)) < 0) {
                       ^~~
/home/gaston/ledshared/exer_simple_char_drv.c:30:9: note: expected ‘struct inode *’ but argument is of type ‘char *’
 ssize_t exer_open(struct inode *pinode, struct file *pfile) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c: In function ‘exer_read’:
/home/gaston/ledshared/exer_simple_char_drv.c:48:16: warning: passing argument 1 of ‘exer_read’ makes pointer from integer without a cast [-Wint-conversion]
  rb= exer_read(file, &ev, sizeof(ev));
                ^~~~
/home/gaston/ledshared/exer_simple_char_drv.c:44:9: note: expected ‘struct file *’ but argument is of type ‘int’
 ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:48:22: error: passing argument 2 of ‘exer_read’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  rb= exer_read(file, &ev, sizeof(ev));
                      ^
/home/gaston/ledshared/exer_simple_char_drv.c:44:9: note: expected ‘char *’ but argument is of type ‘struct input_event (*)[64]’
 ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:48:6: error: too few arguments to function ‘exer_read’
  rb= exer_read(file, &ev, sizeof(ev));
      ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:44:9: note: declared here
 ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:62:6: error: implicit declaration of function ‘eval_keycode’ [-Werror=implicit-function-declaration]
      eval_keycode(ev[yalv].code);
      ^~~~~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c: In function ‘exer_close’:
/home/gaston/ledshared/exer_simple_char_drv.c:101:13: warning: passing argument 1 of ‘exer_close’ makes pointer from integer without a cast [-Wint-conversion]
  exer_close(file);
             ^~~~
/home/gaston/ledshared/exer_simple_char_drv.c:99:9: note: expected ‘struct inode *’ but argument is of type ‘int’
 ssize_t exer_close(struct inode *pinode, struct file *pfile) {
         ^~~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:101:2: error: too few arguments to function ‘exer_close’
  exer_close(file);
  ^~~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:99:9: note: declared here
 ssize_t exer_close(struct inode *pinode, struct file *pfile) {
/home/gaston/ledshared/exer\u simple\u char\u drv.c:在函数“exer\u open”中:
/home/gaston/ledshared/exer\u simple\u char\u drv.c:34:23:错误:从不兼容的指针类型传递“exer\u open”的参数1[-Werror=不兼容的指针类型]
如果((file=exer\u open(str,O\rdu only))<0){
^~~
/home/gaston/ledshared/exer\u simple\u char\u drv.c:30:9:注意:应为“struct inode*”,但参数的类型为“char*”
ssize_t exer_open(结构索引节点*pinode,结构文件*pfile){
^~~~~~~~~
/home/gaston/ledshared/exer\u simple\u char\u drv.c:在函数“exer\u read”中:
/home/gaston/ledshared/exer\u simple\u char\u drv.c:48:16:警告:传递'exer\u read'的参数1会从整数生成指针,而无需强制转换[-Wint转换]
rb=exer_read(文件,&ev,sizeof(ev));
^~~~
/home/gaston/ledshared/exer\u simple\u char\u drv.c:44:9:注意:应为“struct file*”,但参数的类型为“int”
ssize\u t exer\u read(结构文件*pfile,字符*user*缓冲区,大小\u t长度,loff\u t*偏移量){
^~~~~~~~~
/home/gaston/ledshared/exer\u simple\u char\u drv.c:48:22:错误:从不兼容的指针类型传递'exer\u read'的参数2[-Werror=不兼容的指针类型]
rb=exer_read(文件,&ev,sizeof(ev));
^
/home/gaston/ledshared/exer\u simple\u char\u drv.c:44:9:注意:应为“char*”,但参数类型为“struct input\u event(*)[64]”
ssize\u t exer\u read(结构文件*pfile,字符*user*缓冲区,大小\u t长度,loff\u t*偏移量){
^~~~~~~~~
/home/gaston/ledshared/exer\u simple\u char\u drv.c:48:6:错误:函数“exer\u read”的参数太少
rb=exer_read(文件,&ev,sizeof(ev));
^~~~~~~~~
/home/gaston/ledshared/exer\u simple\u char\u drv.c:44:9:注:此处声明
ssize\u t exer\u read(结构文件*pfile,字符*user*缓冲区,大小\u t长度,loff\u t*偏移量){
^~~~~~~~~
/home/gaston/ledshared/exer\u simple\u char\u drv.c:62:6:错误:函数“eval\u keycode”的隐式声明[-Werror=隐式函数声明]
评估键代码(ev[yalv].代码);
^~~~~~~~~~~~
/home/gaston/ledshared/exer\u simple\u char\u drv.c:在函数“exer\u close”中:
/home/gaston/ledshared/exer\u simple\u char\u drv.c:101:13:警告:传递'exer\u close'的参数1会从整数生成指针,而无需强制转换[-Wint转换]
执行关闭(文件);
^~~~
/home/gaston/ledshared/exer\u simple\u char\u drv.c:99:9:注意:应为“struct inode*”,但参数的类型为“int”
ssize\u t exer\u close(结构索引节点*pinode,结构文件*pfile){
^~~~~~~~~~
/home/gaston/ledshared/exer\u simple\u char\u drv.c:101:2:错误:函数“exer\u close”的参数太少
执行关闭(文件);
^~~~~~~~~~
/home/gaston/ledshared/exer\u simple\u char\u drv.c:99:9:注:此处声明
ssize\u t exer\u close(结构索引节点*pinode,结构文件*pfile){
^~~~~~~~~~


有人能帮帮我吗。谢谢你

你有一个名为
exer\u open
的函数。在它里面你试图调用
exer\u open
。你觉得这样对吗?也许你做了一个查询替换,将
open
的所有实例替换为
exer\u open
(其他所有函数也是如此)?我认为交叉编译是这段代码中最小的问题。它看起来像是用户模式和内核模式代码的混合体。@Someprogrammerdude是的,你是对的,这不是逻辑。那么我应该在这里做什么?“是的,你是对的,这不是逻辑。那么我应该在这里做什么?”因为这是“非逻辑”,我们猜不到你想要什么,所以我们不能告诉你该怎么做。
/home/gaston/ledshared/exer_simple_char_drv.c: In function ‘exer_open’:
/home/gaston/ledshared/exer_simple_char_drv.c:34:23: error: passing argument 1 of ‘exer_open’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  if((file = exer_open(str, O_RDONLY)) < 0) {
                       ^~~
/home/gaston/ledshared/exer_simple_char_drv.c:30:9: note: expected ‘struct inode *’ but argument is of type ‘char *’
 ssize_t exer_open(struct inode *pinode, struct file *pfile) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c: In function ‘exer_read’:
/home/gaston/ledshared/exer_simple_char_drv.c:48:16: warning: passing argument 1 of ‘exer_read’ makes pointer from integer without a cast [-Wint-conversion]
  rb= exer_read(file, &ev, sizeof(ev));
                ^~~~
/home/gaston/ledshared/exer_simple_char_drv.c:44:9: note: expected ‘struct file *’ but argument is of type ‘int’
 ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:48:22: error: passing argument 2 of ‘exer_read’ from incompatible pointer type [-Werror=incompatible-pointer-types]
  rb= exer_read(file, &ev, sizeof(ev));
                      ^
/home/gaston/ledshared/exer_simple_char_drv.c:44:9: note: expected ‘char *’ but argument is of type ‘struct input_event (*)[64]’
 ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:48:6: error: too few arguments to function ‘exer_read’
  rb= exer_read(file, &ev, sizeof(ev));
      ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:44:9: note: declared here
 ssize_t exer_read(struct file *pfile, char __user *buffer, size_t length, loff_t *offset) {
         ^~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:62:6: error: implicit declaration of function ‘eval_keycode’ [-Werror=implicit-function-declaration]
      eval_keycode(ev[yalv].code);
      ^~~~~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c: In function ‘exer_close’:
/home/gaston/ledshared/exer_simple_char_drv.c:101:13: warning: passing argument 1 of ‘exer_close’ makes pointer from integer without a cast [-Wint-conversion]
  exer_close(file);
             ^~~~
/home/gaston/ledshared/exer_simple_char_drv.c:99:9: note: expected ‘struct inode *’ but argument is of type ‘int’
 ssize_t exer_close(struct inode *pinode, struct file *pfile) {
         ^~~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:101:2: error: too few arguments to function ‘exer_close’
  exer_close(file);
  ^~~~~~~~~~
/home/gaston/ledshared/exer_simple_char_drv.c:99:9: note: declared here
 ssize_t exer_close(struct inode *pinode, struct file *pfile) {