英文:
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 <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,"A 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 integer");
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 a 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("god %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);
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,"A Integer.")
行忘记了';'。
英文:
You forgot ';' at line MODULE_PARM_DESC(my_int,"A Integer.")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论