Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Hello world kernel modul

[es] :: Linux :: Hello world kernel modul

[ Pregleda: 2132 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

daxx

Član broj: 12395
Poruke: 50
*.smin.sezampro.yu.

ICQ: 167771596


Profil

icon Hello world kernel modul01.04.2007. u 15:43 - pre 207 meseci
Ćao...

Pokušavam da kompajliram ovaj jednostavan modul (kod je iz knjige Linux Device Drivers):

Code:

#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
    printk(KERN_ALERT "Hello, world\n");
    return 0;
}
static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);


Međutim, gcc se nešto ljuti:

Citat:

root@1[Desktop]# gcc hello.c
In file included from /usr/include/linux/sched.h:16,
from /usr/include/linux/module.h:9,
from hello.c:2:
/usr/include/linux/signal.h:2:2: warning: #warning "You should include <signal.h>. This time I will do it for you."
In file included from /usr/include/linux/resource.h:4,
from /usr/include/linux/sched.h:79,
from /usr/include/linux/module.h:9,
from hello.c:2:
/usr/include/linux/time.h:9: error: redefinition of 'struct timespec'
/usr/include/linux/time.h:15: error: redefinition of 'struct timeval'
/usr/include/linux/time.h:20: error: redefinition of 'struct timezone'
/usr/include/linux/time.h:47: error: redefinition of 'struct itimerval'
In file included from hello.c:2:
/usr/include/linux/module.h:41: error: field 'attr' has incomplete type
/usr/include/linux/module.h:49: error: field 'kobj' has incomplete type
hello.c: In function 'hello_init':
hello.c:7: error: 'KERN_ALERT' undeclared (first use in this function)
hello.c:7: error: (Each undeclared identifier is reported only once
hello.c:7: error: for each function it appears in.)
hello.c:7: error: syntax error before string constant
hello.c: In function 'hello_exit':
hello.c:12: error: 'KERN_ALERT' undeclared (first use in this function)
hello.c:12: error: syntax error before string constant


Šta nije u redu? Pretpostavljam da nisam lepo postavio hedere ili nešto slično, ali prilično sam nov u Linux svetu i nisam baš suviše vešt...
Inače, koristim SimplzMEPIS 6.0, a verzija kernela je 2.6.15-26-386.

Hvala unapred.
Dare

EDIT: Čini mi se da u knjizi piše da sami hederi nisu dovoljni, već da mi treba ispravno konfigurisan kernel tree. O čem' se radi?

[Ovu poruku je menjao daxx dana 01.04.2007. u 18:54 GMT+1]
 
Odgovor na temu

stale85
Stanislav Antic
Student
Sremčica

Član broj: 6670
Poruke: 120
*.cri.co.yu.



Profil

icon Re: Hello world kernel modul03.04.2007. u 07:23 - pre 207 meseci
Instaliraj izvorni kod kernela. U /usr/src/linux/, ili preko package manager-a,
$sudo apt-get install linux-source
Ken Thompson has an automobile which he helped design. Unlike most automobiles, it has neither speedometer, nor gas gauge, nor any of the other numerous idiot lights which plague the modern driver. Rather, if the driver makes a mistake, a giant “?” lights up in the center of the dashboard. “The experienced driver,” says Thompson, “will usually know what’s wrong.”
 
Odgovor na temu

[es] :: Linux :: Hello world kernel modul

[ Pregleda: 2132 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.