[C] probleme avec un header ...

Résolu/Fermé
strato-boy Messages postés 764 Date d'inscription mercredi 11 février 2009 Statut Membre Dernière intervention 19 janvier 2011 - 8 oct. 2010 à 22:32
strato-boy Messages postés 764 Date d'inscription mercredi 11 février 2009 Statut Membre Dernière intervention 19 janvier 2011 - 9 oct. 2010 à 21:17
salut la compagnie !

j'ai un pitit probleme avec un de mes piti code en C ...
voila j'ai voulu essayer de faire un code avec un petit headers a ma sauce pour voir si ça marché
et dont voici le code (nom du fichier : libstratos.h) :
#ifndef LIBSTRATOS_H_INCLUDED
#define LIBSTRATOS_H_INCLUDED

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

//une pause de x secondes
void mon_sleep(double nbresec);

//lecture propre du clavier
int lire_clavier(char *str, int taille);

#endif


il est bien entendu relié a un fichier libstratos.c contenant les 2 fonction dont on voit les prototypes.

a coté de ça, mon main.c, lui ressemble a ça :
#include "libstratos.h"

void affiche_table(void)
{
    int counter=0;
    printf("test.1\n");
    for(counter=0;counter<4;counter++)
    {
        printf("test.2\n");
        mon_sleep(1);
    }
}

int main(void)
{
    affiche_table();
    exit(EXIT_SUCCESS);
}


rien de bien compiqué quoi
mais, a la compilation, GCC me lance(entre autre ) cela :

warning: implicit declaration of function `printf'
 warning: implicit declaration of function `exit'
error: `EXIT_SUCCESS' undeclared (first use in this function)


bien entendu, les fichier sont tous dans le meme dossier...

bref, j'aurais pensé qu'en appelant libstratos.h, qui elle même appelle stdio.h et stdlib.h
je n'aurais pas de probleme ...

qu'en pensez vous ? ou ai-je pu faire une errreur ?
merci de votre aide ;)

1 réponse

dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
9 oct. 2010 à 09:01
hello
si tu compiles avec -D LIBSTRATOS_H_INCLUDED #ifndef LIBSTRATOS_H_INCLUDED est faux, il ne va donc pas exécuter
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
0
strato-boy Messages postés 764 Date d'inscription mercredi 11 février 2009 Statut Membre Dernière intervention 19 janvier 2011 100
9 oct. 2010 à 10:14
merci de ton attention mais je n'utilise pas cette option pour compilé, j'utilise :

gcc -Wall libstratos.c libstratos.h main.c -o test
0
dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
9 oct. 2010 à 11:04
il ne faut compiler que le fichier .c
gcc -Wall libstratos.c -o test
il manque le fichier avec mon_sleep
0
strato-boy Messages postés 764 Date d'inscription mercredi 11 février 2009 Statut Membre Dernière intervention 19 janvier 2011 100
9 oct. 2010 à 21:17
arff effectivement, en ne compilant que le main.c ça marche, je pensé qu'il fallait tout mettre ... merci bien en tout cas !!
0