我为名为 example1.c 的内核创建了简单模块的源代码
#include linux/module.h
static int __init _init_(void)
{
printk(KERN_INFO"Hello");
return 0;
}
static void __exit _exit_(void)
{
printk(KERN_INFO"bye\n");
}
module_init(_init_);
module_exit(_exit_);
之后我想以这种方式编译它来创建目标文件(我的意思是 example1.o)
gcc -Wall -o example1.c example1
但我不能这样做,我收到了这个错误
example1: file not recognized: file format not recognized
答案1
当我输出exampleone
而不是example1
这样时:gcc example1.c -o exampleone
我不再得到
gcc: error: gcc: No such file or directory
gcc: error: example1: No such file or directory
gcc: fatal error: no input files
我自己编译代码时遇到这些错误:
example1.c:1:11: error: #include expects "FILENAME" or <FILENAME>
1 | #include linux/module.h
| ^~~~~
example1.c:3:20: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_init_’
3 | static int __init _init_(void)
| ^~~~~~
example1.c:9:21: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘_exit_’
9 | static void __exit _exit_(void)
| ^~~~~~
example1.c:16:2: warning: data definition has no type or storage class
16 | module_init(_init_);
| ^~~~~~~~~~~
example1.c:16:2: warning: type defaults to ‘int’ in declaration of ‘module_init’ [-Wimplicit-int]
example1.c:16:2: warning: parameter names (without types) in function declaration
example1.c:17:2: warning: data definition has no type or storage class
17 | module_exit(_exit_);
| ^~~~~~~~~~~
example1.c:17:2: warning: type defaults to ‘int’ in declaration of ‘module_exit’ [-Wimplicit-int]
example1.c:17:2: warning: parameter names (without types) in function declaration
让我知道这是否可以解决您的问题。如果没有,请告诉我,我将删除此答案。最后一件事,确保您位于终端中的正确目录中。