Getting 'expected ',' or ';' before static' error in moduleparam.h while compiling a kernel module on Ubuntu

huangapple go评论63阅读模式
英文:

Getting 'expected ',' or ';' before static' error in moduleparam.h while compiling a kernel module on Ubuntu

问题

在编写Ubuntu上的简单内核模块时,我遇到了以下错误,位于文件moduleparam.h中,如下所示:

./include/linux/moduleparam.h:409:9: error: expected , or ; before static

以下是我尝试编译的代码:

#include <linux/module.h>
#include <linux/printk.h>
#include <linux/init.h>
#include <linux/kernel.h> //This for an ARRAY_SIZE()
#include <linux/moduleparam.h> //Module parameters 
#include <linux/stat.h>;

MODULE_LICENSE("GPL");

static short my_short = 1;
static long my_long = 9999;
static int my_int = 5;
static char *my_string = "WH";
static int my_array[2] = {429, 429};
static int arr_argc = 0;

module_param(my_short, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
MODULE_PARM_DESC(my_short, "A short integer.");
module_param(my_long, long, S_IRUSR);
MODULE_PARM_DESC(my_long, "A long Integer.");
module_param(my_int, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
MODULE_PARM_DESC(my_int, "An Integer.");
module_param(my_string, charp, 0000);
MODULE_PARM_DESC(my_string, "A character string");
module_param_array(my_array, int, &arr_argc, 0000);
MODULE_PARM_DESC(my_array, "An Array of integers");

static int __init start_module(void)
{
    int i;
    pr_info("Hello, World 5.\n ======================\n");
    pr_info("My_Short is a short integer %d\n", my_short);
    pr_info("My_long is a long integer %d\n", my_long);
    pr_info("My_int is an integer %d\n", my_int);
    pr_info("My_string is a character string %s\n", my_string);

    for (i = 0; i < ARRAY_SIZE(my_array); i++)
        pr_info("At index %d, we have %d in my_array\n", i, my_array[i]);
    pr_info("got %d arguments in the my_array\n", arr_argc);
    return 0;
}

static void __exit end_module(void)
{
    pr_info("Goodbye! world 5\n");
}

module_init(start_module);
module_exit(end_module);

我尝试定位文件moduleparam.h并修复了这个问题,但我认为我目前的编程知识不足以解决它。

英文:

While writing a simple kernel module on Ubuntu, I came across the below error in the file moduleparam.h as below

./include/linux/moduleparam.h:409:9: error: expected ‘,’ or ‘;’ before ‘static’ 

below is the code I am trying to compile.

#include &lt;linux/module.h&gt;
#include &lt;linux/printk.h&gt;
#include &lt;linux/init.h&gt;
#include &lt;linux/kernel.h&gt; //This for an ARRAY_SIZE()
#include &lt;linux/moduleparam.h&gt; //Module parameters 
#include &lt;linux/stat.h&gt;

MODULE_LICENSE(&quot;GPL&quot;);

static short my_short = 1;
static long my_long = 9999;
static int my_int = 5;
static char *my_string = &quot;WH&quot;;
static int my_array[2] = {429,429};
static int arr_argc = 0;


module_param(my_short,short,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
MODULE_PARM_DESC(my_short,&quot;A short integer.&quot;);
module_param(my_long,long,S_IRUSR);
MODULE_PARM_DESC(my_long,&quot;A long Integer.&quot;);
module_param(my_int,int,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
MODULE_PARM_DESC(my_int,&quot;A Integer.&quot;)
module_param (my_string,charp,0000);
MODULE_PARM_DESC(my_string,&quot;A character string&quot;);
module_param_array (my_array,int, &amp;arr_argc,0000);
MODULE_PARM_DESC(my_array,&quot;An Array of integer&quot;);



static int __init start_module(void)
{   
    int i;
    pr_info(&quot;Hello, World 5.\n ======================\n&quot;);
    pr_info(&quot;My_Short is a short integer %d\n&quot;,my_short);
    pr_info(&quot;My_long is a long integer %d\n&quot;,my_long);
    pr_info(&quot;My_int is a  integer %d\n&quot;,my_int);
    pr_info(&quot;My_string is a character string %s\n&quot;,my_string);

    for (i=0;i &lt; ARRAY_SIZE(my_array);i++)
        pr_info (&quot;At index %d, we have %d in my_array\n&quot;,i,my_array[i]);
    pr_info(&quot;god %d arguments in the my_array\n&quot;,arr_argc);
    return 0;

}

static void __exit end_module(void)
{
    pr_info(&quot;GoodBye! world 5\n&quot;);
}

module_init(start_module);
module_exit(end_module);

I tried to locate the file moduleparam.h and fix the issue, but i think i dont hold that much programming knowledge at the moment.

答案1

得分: 4

你在第 MODULE_PARM_DESC(my_int,&quot;A Integer.&quot;) 行忘记了';'。

英文:

You forgot ';' at line MODULE_PARM_DESC(my_int,&quot;A Integer.&quot;)

huangapple
  • 本文由 发表于 2023年5月25日 05:58:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76327658.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定