2017-12-09 11 views
0

에 장치 드라이버를 컴파일,하지만 난 다음 오류, 내가 사용하여 다음을 프로그램을 컴파일러
나는 장치 드라이버를 컴파일하기 위해 노력하고있어 커널

[email protected]:~/Desktop$ make 
make -C /lib/modules/4.13.0-19-generic/build M=/home/ddd/Desktop modules 
make[1]: Entering directory '/usr/src/linux-headers-4.13.0-19-generic' 
    CC [M] /home/ddd/Desktop/message_slot.o 
/home/ddd/Desktop/message_slot.c:23:10: fatal error: stdio.h: No such file or directory 
#include <stdio.h> 
      ^~~~~~~~~ 
compilation terminated. 
scripts/Makefile.build:309: recipe for target '/home/ddd/Desktop/message_slot.o' failed 
make[2]: *** [/home/ddd/Desktop/message_slot.o] Error 1 
Makefile:1546: recipe for target '_module_/home/ddd/Desktop' failed 
make[1]: *** [_module_/home/ddd/Desktop] Error 2 
make[1]: Leaving directory '/usr/src/linux-headers-4.13.0-19-generic' 
Makefile:5: recipe for target 'all' failed 
make: *** [all] Error 2 
[email protected]:~/Desktop$ 

다음의 모든 헤더 같은 하나를 얻을 메이크 :

obj-m := message_slot.o 
KDIR := /lib/modules/$(shell uname -r)/build 
PWD := $(shell pwd) 
all: 
    $(MAKE) -C $(KDIR) M=$(PWD) modules 
clean: 
    $(MAKE) -C $(KDIR) M=$(PWD) clean 

것은, 즉 작은 .c 인 코드를 실행하여 :

#include <stdio.h> 
#include <stdli.h> 

int main(){ 
    printf("test"); 
} 


gcc test.c -o test
모든 것이 컴파일됩니다. 커널 헤더가있는 것으로 의심되지만 모든 헤더를 지정된대로 다운로드했습니다. 나는 윤활유를 타고있다 17.10
내가 뭔가를 놓친가요?
덕분에 많은

+1

가능한 [장치 드라이버 내에서 stdlib.h 사용] (https://stackoverflow.com/questions/23150611/using-stdlib-h-within-a-device-driver) 중복 가능성 있음 –

+0

생각하지 않습니다. 중복, 왜냐하면 내가 문제를 정확하게 식별 할 수 없지만 완전히 내 문제를 해결했습니다. 고마워요. – DsCpp

+0

[커널 오류 컴파일 : stdio.h : 해당 파일이나 디렉토리가 없습니다.] (https://stackoverflow.com/questions/10345778/compiling-kernel-error-stdio-h-no-such-file) - 또는 - 디렉토리) – Tsyvarev

답변

2

stdio.hmake 실패 이유입니다, 사용자 공간 헤더 파일이 커널 공간이 아니다. 드라이버 프로그램에서 을 포함하고 있는데 왜냐하면 bcz가 main() 기능을 가지고 있지 않기 때문입니다. 맞습니까? 당신이 make을 할 때

관찰하여 makefile 당신이 모듈로 컴파일하고 소스 코드를 /usr/src/linux-4 (일부 버전)에있을 것입니다 의미

obj-m := message_slot.o 
KDIR := /lib/modules/$(shell uname -r)/build 

. 예를 들어 대한

#include <linux/stat.h> 

하지

#include <stat.h> 

왜 당신은 당신의 printf를 사용하지 않을 때문에 stdio.h에 포함되는 드라이버 프로그램에서

[email protected]:/usr/src/linux-4.1.39/include/linux$ ls -l stdio.h 
     ls: cannot access stdio.h: No such file or directory 

대신을 printk()? 당신이 modulefile하지 gcc 컴파일러를 사용하여 컴파일하기 때문에 응용 프로그램에서

예는 stdio.h를 포함 할 수 있습니다.

도움이되기를 바랍니다.