IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Debian Discussion :

programmation module kernel


Sujet :

Debian

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de rufa11
    Consultant informatique
    Inscrit en
    Décembre 2007
    Messages
    300
    Détails du profil
    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 300
    Par défaut programmation module kernel
    Bonjour, j'ai compilé un programme kernel qui affiche hello word:

    hello.c
    * Copyright (C) 1998 by Ori Pomerantz
    *
    * "Hello, world" - the kernel module version.
    */
    /* The necessary header files */
    /* Standard in kernel modules */
    #include <linux/kernel.h> /* We’re doing kernel work */
    #include <linux/module.h> /* Specifically, a module */
    /* Deal with CONFIG_MODVERSIONS */
    #if CONFIG_MODVERSIONS==1
    #define MODVERSIONS
    #include <linux/modversions.h>
    #endif
    /* Initialize the module */
    int init_module()
    {
    printk("Hello, world - this is the kernel speaking\n");
    /* If we return a non zero value, it means that
    * init_module failed and the kernel module
    * can’t be loaded */
    return 0;
    }
    /* Cleanup - undid whatever init_module did */
    void cleanup_module()
    {
    printk("Short is the life of a kernel module\n");
    }

    les erreurs suivantes son apparus:

    abdelkader@abdelkader:~$ make hello
    cc hello.c -o hello
    In file included from /usr/include/asm-i486/local.h:4,


    from /usr/include/asm/local.h:8,


    from /usr/include/linux/module.h:20,


    from hello.c:2:
    /usr/include/linux/percpu.h: In function ‘__alloc_percpu’:
    /usr/include/linux/percpu.h:44: error: ‘GFP_KERNEL’ undeclared (first use in this function)
    /usr/include/linux/percpu.h:44: error: (Each undeclared identifier is reported only once
    /usr/include/linux/percpu.h:44: error: for each function it appears in.)
    In file included from /usr/include/asm/module.h:8,

    from /usr/include/linux/module.h:22,

    from hello.c:2:
    /usr/include/asm-i486/module.h:60:2: error: #error unknown processor family
    In file included
    from hello.c:2:
    /usr/include/linux/module.h: At top level:
    /usr/include/linux/module.h:49: error: field ‘attr’ has incomplete type
    /usr/include/linux/module.h:60: error: field ‘kobj’ has incomplete type
    make: *** [hello] Erreur 1

    le fichier make file :

    # Makefile for a basic kernel module
    CC=gcc
    MODCFLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX
    hello.o: hello.c /usr/include/linux/version.h
    $(CC) $(MODCFLAGS) -c hello.c
    echo insmod hello.o to turn it on
    echo rmmod hello to turn if off
    echo
    echo X and kernel programming do not mix.
    echo Do the insmod and rmmod from outside X.


    la distribution est debian version 4.0.
    svp je veut comprend les erreurs pour que je puisse les résoudre.

  2. #2
    Membre éclairé Avatar de rufa11
    Consultant informatique
    Inscrit en
    Décembre 2007
    Messages
    300
    Détails du profil
    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 300
    Par défaut
    salut,on ma dit le kernel a beacoup changer depuis 1999 (la date de ce programme)alors j'ai compilé avec la version du kernel 2.6 "http://www.tldp.org/LDP/lkmpg/"
    le programme est :

    /*

    * hello-1.c - The simplest kernel module.

    */
    #include <linux/module.h> /* Needed by all modules */
    #include <linux/kernel.h> /* Needed for KERN_INFO */

    int init_module(void)
    {
    printk(KERN_INFO "Hello world 1.n");

    /*

    * A non 0 return means init_module failed; module can't be loaded.

    */
    return 0;
    }

    void cleanup_module(void)
    {
    printk(KERN_INFO "Goodbye world 1.n");
    }
    mais dans la compilation avec make les erreurs:
    cc hello.c -o hello
    In

    file included from /usr/include/asm-i486/local.h:4,

    from /usr/include/asm/local.h:8,

    from /usr/include/linux/module.h:20,

    from hello.c:2:
    /usr/include/linux/percpu.h: In function ‘__alloc_percpu’:

    /usr/include/linux/percpu.h:44: error: ‘GFP_KERNEL’ undeclared (first use in this function)
    /usr/include/linux/percpu.h:44: error: (Each undeclared identifier is reported only once
    /usr/include/linux/percpu.h:44: error: for each function it appears in.)

    In file included from
    /usr/include/asm/module.h:8,

    from /usr/include/linux/module.h:22,

    from hello.c:2:
    /usr/include/asm-i486/module.h:60:2: error: #error unknown processor family
    In file included from hello.c:2:
    /usr/include/linux/module.h: At top level:

    /usr/include/linux/module.h:49: error: field ‘attr’ has incomplete type

    /usr/include/linux/module.h:60: error: field ‘kobj’ has incomplete type

    hello.c: In function ‘init_module’:
    hello.c:6: error: ‘KERN_INFO’ undeclared (first use in this function)

    hello.c:6: error: expected ‘)’ before string constant

    hello.c: In function ‘cleanup_module’:

    hello.c:12: error: ‘KERN_INFO’ undeclared (first use in this function)

    hello.c:12: error: expected ‘)’ before string constant

    hello.c:13:2: warning: no newline at end of file

    make: *** [hello] Erreur 1

    alors j'ai supprimé KERN INFO alors le résultat est :

    cc hello.c -o hello

    In file included from
    /usr/include/asm-i486/local.h:4,

    from /usr/include/asm/local.h:8,
    from /usr/include/linux/module.h:20,
    from hello.c:2:
    /usr/include/linux/percpu.h: In function ‘__alloc_percpu’:

    /usr/include/linux/percpu.h:44: error: ‘GFP_KERNEL’ undeclared (first use in this function)
    /usr/include/linux/percpu.h:44: error: (Each undeclared identifier is reported only once
    /usr/include/linux/percpu.h:44: error: for each function it appears in.)

    In file included from
    /usr/include/asm/module.h:8,

    from /usr/include/linux/module.h:22,

    from hello.c:2:
    /usr/include/asm-i486/module.h:60:2: error: #error unknown processor family

    In file included from
    hello.c:2:
    /usr/include/linux/module.h: At top level:

    /usr/include/linux/module.h:49: error: field ‘attr’ has incomplete type

    /usr/include/linux/module.h:60: error: field ‘kobj’ has incomplete type

    hello.c:13:2: warning: no newline at end of file

    make: *** [hello] Erreur 1

    le fichier Makefile est :
    obj-m += hello-1.o

    all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

    clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

    svp aidai moi c'est pour mon projet de fin d'étude,merci d'avance.

  3. #3
    Membre éclairé Avatar de rufa11
    Consultant informatique
    Inscrit en
    Décembre 2007
    Messages
    300
    Détails du profil
    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Décembre 2007
    Messages : 300
    Par défaut
    pour: hello.c:13:2: warning: no newline at end of file
    c'est résolu,il suffit d'aller a la dernière ligne du programme et d'appuyer sur entre,il reste le plus difficile.

Discussions similaires

  1. conseil pour la programmation des modules kernel
    Par rufa11 dans le forum Applications et environnements graphiques
    Réponses: 0
    Dernier message: 25/10/2008, 17h50
  2. documentation sur les modules kernel
    Par rufa11 dans le forum Linux
    Réponses: 0
    Dernier message: 08/10/2008, 21h31
  3. comment compiler un module kernel ?
    Par rufa11 dans le forum RedHat / CentOS / Fedora
    Réponses: 14
    Dernier message: 17/09/2008, 16h32
  4. Réponses: 0
    Dernier message: 10/04/2008, 10h56
  5. module kernel NAT pour le protocole SIP
    Par star31 dans le forum Linux
    Réponses: 0
    Dernier message: 27/01/2008, 17h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo