SoloCodigo

Programación General => C/C++ => Mensaje iniciado por: Begeo en Domingo 20 de Enero de 2008, 19:21

Título: Programación De Kernel
Publicado por: Begeo en Domingo 20 de Enero de 2008, 19:21
Hola.

Empecé a mirarme guías de programación de kernel para linux, y encontré una bastante buena. Llegué al punto 2.2, e hice el "hello world" tal y como dijo el tutorial:

Código: Text
  1. /* My first kernel module
  2. OMFG */
  3. #include <linux/module.h> /*It's required for modulessssssss!*/
  4. #include <linux/kernel.h> /*It's required to give the errooooooor */
  5.  
  6. int init_module(void)
  7. {
  8.    printk("<1>Hello world 1.\n");
  9.  
  10.    // Let's see, this tutorial says that not returning 0, means the module cant be loaded. Great.
  11.    return 0;
  12. }
  13.  
  14. void cleanup_module(void)
  15. {
  16.    printk(KERN_ALERT "OMFG THE WORLD GONE TO SHIT!.\n");
  17. }
  18.  
El problema está en los #include, exactamente #include <linux/module.h>, que no me lo reconoce el compilador de gcc.

Leí por ahí que tenia que tener mi propia versión del kernel compilado, pero no tengo ni idea de cómo hacerlo (Help plox?).¿Me pueden decir cómo puedo solucionar mi problema?
Citar
gcc '/home/begeo/デスクトップ/kernelmod.c' -W -Wall -Wstrict-prototypes -Wmissing-prototypes -isystem /lib/modules'uname -r'/build/include -02 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE}
gcc: unrecognized option '-02'
/home/begeo/デスクトップ/kernelmod.c:3:64: error: linux/module.h: No such file or directory
/home/begeo/デスクトップ/kernelmod.c:7: 警告: no previous prototype for ‘init_module’
/home/begeo/デスクトップ/kernelmod.c: In function ‘init_module’:
/home/begeo/デスクトップ/kernelmod.c:8: 警告: implicit declaration of function ‘printk’
/home/begeo/デスクトップ/kernelmod.c: トップレベル:
/home/begeo/デスクトップ/kernelmod.c:15: 警告: no previous prototype for ‘cleanup_module’
/home/begeo/デスクトップ/kernelmod.c: In function ‘cleanup_module’:
/home/begeo/デスクトップ/kernelmod.c:16: error: ‘KERN_ALERT’ undeclared (first use in this function)
/home/begeo/デスクトップ/kernelmod.c:16: error: (Each undeclared identifier is reported only once
/home/begeo/デスクトップ/kernelmod.c:16: error: for each function it appears in.)
/home/begeo/デスクトップ/kernelmod.c:16: error: expected ‘)’ before string constant

¿Ayuda?

PD: Estoy intentando usar el kernel de linu, compilando desde linux.
Título: Re: Programación De Kernel
Publicado por: Eternal Idol en Domingo 20 de Enero de 2008, 19:54
Baja y compila Linux (es un Kernel).

http://www.kernel.org/ (http://www.kernel.org/)
http://kernelnewbies.org/ (http://kernelnewbies.org/)