![모듈 컴파일 문제: "대상 생성 규칙이 없습니다."](https://linux55.com/image/188709/%EB%AA%A8%EB%93%88%20%EC%BB%B4%ED%8C%8C%EC%9D%BC%20%EB%AC%B8%EC%A0%9C%3A%20%22%EB%8C%80%EC%83%81%20%EC%83%9D%EC%84%B1%20%EA%B7%9C%EC%B9%99%EC%9D%B4%20%EC%97%86%EC%8A%B5%EB%8B%88%EB%8B%A4.%22.png)
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
문제가 해결되면 알려주세요. 그렇지 않은 경우 알려주시면 이 답변을 삭제하겠습니다. 마지막으로, 터미널의 올바른 디렉토리에 있는지 확인하세요.