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

 C Discussion :

MakeFile minimal difficultées


Sujet :

C

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    70
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 70
    Points : 38
    Points
    38
    Par défaut MakeFile minimal difficultées
    Bonjour,

    J'ai quelques difficultés à bien maitriser le makefile,j'ai fait ça(code en dessous):


    Au total, j'ai panorama qui est le programme principale, puis d'autre fichier
    contenant des fonctions ou prototype pour les .h.
    Le problème est que ça ne marche pas, donc j'ai dû mal comprendre quelque chose...
    (N.b.:je suis obligé de mettre le -lm, sinon la biblio maths ne charge pas)

    Je vous remercie d'avance pour votre aide !

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
     
     
    panorama: panorama.o Function.o Parser.o
    	gcc -o panorama panorama.o Function.o Parser.o -lm
     
    panorama.o: panorama.c 
    	gcc -o panorama.o -c panorama.c -W -Wall -ansi -pedantic
     
    Function.o: Function.c Function.h 
    	gcc -o Function.o -c Function.c -W -Wall -ansi -pedantic
     
    Parser.o: Parser.c Parser.h
    	gcc -o Parser.o -c Parser.c -W -Wall -ansi -pedantic

  2. #2
    Expert éminent sénior
    Avatar de Sve@r
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2006
    Messages
    12 689
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 12 689
    Points : 30 983
    Points
    30 983
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par bouritosse Voir le message
    Bonjour,

    J'ai quelques difficultés à bien maitriser le makefile,j'ai fait ça(code en dessous):


    Au total, j'ai panorama qui est le programme principale, puis d'autre fichier
    contenant des fonctions ou prototype pour les .h.
    Le problème est que ça ne marche pas, donc j'ai dû mal comprendre quelque chose...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
     
     
    panorama: panorama.o Function.o Parser.o
    gcc -o panorama panorama.o Function.o Parser.o -lm
     
    panorama.o: panorama.c
    gcc -o panorama.o -c panorama.c -W -Wall -ansi -pedantic
     
    Function.o: Function.c Function.h
    gcc -o Function.o -c Function.c -W -Wall -ansi -pedantic
     
    Parser.o: Parser.c Parser.h
    gcc -o Parser.o -c Parser.c -W -Wall -ansi -pedantic
    Salut
    A première vue, ce makefile me parait correct (toutefois l'option "-c" de gcc ne nécessite pas de "-o" => peut-être que "-o" n'est pas compatible avec "-c"...).

    Donc "qu'est-ce qui ne marche pas" et comment cela se traduit dans ta compilation ???

    Citation Envoyé par bouritosse Voir le message
    (N.b.:je suis obligé de mettre le -lm, sinon la biblio maths ne charge pas)
    Oui oui, c'est normal. La libm n'est pas incluse par défaut.
    Mon Tutoriel sur la programmation «Python»
    Mon Tutoriel sur la programmation «Shell»
    Sinon il y en a pleins d'autres. N'oubliez pas non plus les différentes faq disponibles sur ce site
    Et on poste ses codes entre balises [code] et [/code]

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2013
    Messages
    70
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2013
    Messages : 70
    Points : 38
    Points
    38
    Par défaut
    Il me sort énormément d'erreur, alors que si je compile uniquement le main tout marche j'ai juste deux warnings
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
     
    Function.c:271:1: error: expected identifier or(’ before ‘/’ token
    Function.c:290:1: error: expected identifier or(’ before ‘/’ token
    Function.c:295:6: warning: missing terminating ' character [enabled by default]
    Function.c:295:1: error: missing terminating ' character
    Function.c: In function ‘matrixByColumnToMatrixP2’:
    Function.c:337:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:329:9: warning: unused variable ‘seuil’ [-Wunused-variable]
    Function.c: In function ‘matrixByColumnToMatrixP3’:
    Function.c:366:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:358:9: warning: unused variable ‘seuil’ [-Wunused-variable]
    Function.c: At top level:
    Function.c:383:1: error: expected identifier or(’ before ‘/’ token
    Function.c: In function ‘transformArrayOfCharInMatrixP2’:
    Function.c:421:5: warning: ISO C90 forbids variable length array ‘lineOfPixel’ [-Wvla]
    Function.c:421:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:418:9: warning: unused variable ‘k’ [-Wunused-variable]
    Function.c: In function ‘transformArrayOfCharInMatrixP3’:
    Function.c:448:5: warning: ISO C90 forbids variable length array ‘lineOfPixel’ [-Wvla]
    Function.c:448:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:445:9: warning: unused variable ‘k’ [-Wunused-variable]
    Function.c: At top level:
    Function.c:470:1: error: expected identifier or(’ before ‘/’ token
    Function.c: In function ‘grayScale’:
    Function.c:539:17: error: expected expression before ‘/’ token
    Function.c: At top level:
    Function.c:559:1: error: expected identifier or(’ before ‘/’ token
    Function.c: In function ‘fileCopyP2’:
    Function.c:619:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:636:9: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c: In function ‘fileCopyP3’:
    Function.c:680:9: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c: At top level:
    Function.c:707:1: error: expected identifier or(’ before ‘/’ token
    In file included from panorama.c:10:0:
    Function.c: In function ‘writeFileWithGrayScale’:
    Function.c:769:5: error: expected expression before ‘/’ token
    Function.c: In function ‘histogram’:
    Function.c:806:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:833:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:791:9: warning: unused variable ‘k’ [-Wunused-variable]
    Function.c: In function ‘getKernel’:
    Function.c:859:23: warning: unused parameter ‘kernel’ [-Wunused-parameter]
    Function.c: In function ‘convolution’:
    Function.c:885:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:898:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c: In function ‘convolutionP3’:
    Function.c:1005:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:1021:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:1060:31: error: expected expression before ‘/’ token
    Function.c: In function ‘dilatation’:
    Function.c:1128:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:1135:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:1121:64: warning: unused parameter ‘kernel’ [-Wunused-parameter]
    Function.c: In function ‘erosion’:
    Function.c:1206:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:1213:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:1199:61: warning: unused parameter ‘kernel’ [-Wunused-parameter]
    Function.c: In function ‘erosionP3’:
    Function.c:1284:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:1294:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:1316:31: error: expected expression before ‘/’ token
    Function.c:1277:63: warning: unused parameter ‘kernel’ [-Wunused-parameter]
    Function.c: In function ‘dilatationP3’:
    Function.c:1363:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:1373:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    Function.c:1395:31: error: expected expression before ‘/’ token
    Function.c:1356:66: warning: unused parameter ‘kernel’ [-Wunused-parameter]
    In file included from panorama.c:12:0:
    Parser.c: In function ‘createTable2’:
    Parser.c:7:19: warning: initialization from incompatible pointer type [enabled by default]
    Parser.c:8:19: warning: initialization from incompatible pointer type [enabled by default]
    panorama.c: In function ‘main’:
    panorama.c:17:5: error: expected expression before ‘/’ token
    panorama.c:18:5: warning: ISO C90 forbids mixed declarations and code [-pedantic]
    panorama.c:43:22: error: expected expression before ‘/’ token
    panorama.c:43:55: warning: missing terminating ' character [enabled by default]
    panorama.c:43:22: error: missing terminating ' character
    panorama.c:55:16: error: expected expression before ‘/’ token
    panorama.c:55:19: warning: missing terminating ' character [enabled by default]
    panorama.c:55:16: error: missing terminating ' character
    panorama.c:161:56: warning: missing terminating ' character [enabled by default]
    panorama.c:161:3: error: missing terminating ' character
    panorama.c:177:56: warning: missing terminating ' character [enabled by default]
    panorama.c:177:3: error: missing terminating ' character
    panorama.c:185:14: error: expected expression before ‘/’ token
    panorama.c:27:10: warning: unused variable ‘temp’ [-Wunused-variable]
    panorama.c:26:10: warning: unused variable ‘kernel’ [-Wunused-variable]
    panorama.c:25:11: warning: unused variable ‘nameOfYourFileO’ [-Wunused-variable]
    panorama.c:24:11: warning: unused variable ‘nameOfYourFile’ [-Wunused-variable]
    panorama.c:23:12: warning: variable ‘tab’ set but not used [-Wunused-but-set-variable]
    panorama.c:21:9: warning: unused variable ‘j’ [-Wunused-variable]
    panorama.c:19:9: warning: unused variable ‘max’ [-Wunused-variable]
    panorama.c:18:9: warning: unused variable ‘e’ [-Wunused-variable]
    panorama.c:15:25: warning: unused parameter ‘argv’ [-Wunused-parameter]
    panorama.c:186:1: warning: control reaches end of non-void function [-Wreturn-type]
    In file included from panorama.c:10:0:
    panorama.c: In function ‘magicNumber’:
    Function.c:56:1: warning: control reaches end of non-void function [-Wreturn-type]
    make: *** [panorama.o] Error 1

  4. #4
    Modérateur
    Avatar de Obsidian
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Septembre 2007
    Messages
    7 370
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2007
    Messages : 7 370
    Points : 23 625
    Points
    23 625
    Par défaut
    Bonjour,

    Citation Envoyé par bouritosse Voir le message
    J'ai quelques difficultés à bien maitriser le makefile,j'ai fait ça(code en dessous):

    Le problème est que ça ne marche pas, donc j'ai dû mal comprendre quelque chose...
    « Ça ne marche pas » n'est pas une description acceptable d'un problème, tu le sais déja. Dis-nous où ça bloque et poste ici les messages d'erreur.

    (EDIT : posté à peu près au même moment que le message précédent).

  5. #5
    Expert éminent sénior
    Avatar de Sve@r
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Février 2006
    Messages
    12 689
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 12 689
    Points : 30 983
    Points
    30 983
    Billets dans le blog
    1
    Par défaut
    Citation Envoyé par bouritosse Voir le message
    Il me sort énormément d'erreur, alors que si je compile uniquement le main tout marche j'ai juste deux warnings
    Commence par supprimer les ".o" et l'exécutable pour partir d'une situation saine.
    Ensuite, teste chaque règle de ton Makefile => make panorama.o puis make Function.o puis make parser.o et regarde laquelle ne fonctionne pas.

    Si tout est ok, teste la dernière => make panorama...
    Mon Tutoriel sur la programmation «Python»
    Mon Tutoriel sur la programmation «Shell»
    Sinon il y en a pleins d'autres. N'oubliez pas non plus les différentes faq disponibles sur ce site
    Et on poste ses codes entre balises [code] et [/code]

  6. #6
    Modérateur
    Avatar de Obsidian
    Homme Profil pro
    Développeur en systèmes embarqués
    Inscrit en
    Septembre 2007
    Messages
    7 370
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Développeur en systèmes embarqués
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2007
    Messages : 7 370
    Points : 23 625
    Points
    23 625
    Par défaut
    Citation Envoyé par bouritosse Voir le message
    Il me sort énormément d'erreur, alors que si je compile uniquement le main tout marche j'ai juste deux warnings
    Question bête : est-ce que tu utilises -W -Wall -ansi -pedantic quand tu compiles à la main ou est-ce que tu ne les passes que dans ton Makefile ?

    Il faudrait qu'on voie ton code pour en être certain mais tous les messages que tu nous montres concernent uniquement la compilation C et ont l'air légitimes.

    Plusieurs choses en particulier :
    • les commentaires débutant par « // » ne sont valides qu'en C99 et pas en C ANSI ;
    • Les déclarations de variables doivent toutes être regroupées en haut d'un bloc (i.e.: une paire d'accolades) avant la première instruction. Ça s'explique par le fait que les premiers compilateurs avaient besoin de cela pour calculer la taille du cadre de pile qui contient entre autres toutes les variables locales à un de ces blocs ;
    • Tout le reste concerne des variables déclarées mais jamais utilisées. Ce n'est pas illégal en soi et ça n'empêchera pas ton programme de compiler, mais ça occupe de l'espace en mémoire pour rien et ça signifie que soit ton programme a été mal conçu, soit tu l'as modifié depuis et oublié de retirer les variables devenues inutiles. Donc, en l'absence d'options le compilateur ne dit rien, mais si tu lui demandes de faire de la compilation stricte, il le fait.

  7. #7
    Inactif  


    Homme Profil pro
    Doctorant sécurité informatique — Diplômé master Droit/Économie/Gestion
    Inscrit en
    Décembre 2011
    Messages
    9 012
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Doctorant sécurité informatique — Diplômé master Droit/Économie/Gestion
    Secteur : Enseignement

    Informations forums :
    Inscription : Décembre 2011
    Messages : 9 012
    Points : 23 145
    Points
    23 145
    Par défaut
    Bonjour,

    panorama: panorama.o Function.o Parser.o
    gcc -o panorama panorama.o Function.o Parser.o -lm

    panorama.o: panorama.c
    gcc -o panorama.o -c panorama.c -W -Wall -ansi -pedantic

    Function.o: Function.c Function.h
    gcc -o Function.o -c Function.c -W -Wall -ansi -pedantic

    Parser.o: Parser.c Parser.h
    gcc -o Parser.o -c Parser.c -W -Wall -ansi -pedantic
    La première chose que je vérifierai, c'est de regarder si tu as bien des tabulation et non des espaces. C'est une source d'erreur assez courante.

    Ensuite, d'après les messages d'erreurs (qu'il faut toujours regarder attentivement avant de faire quoi que ce soit), le problème ne vient pas du Makefile mais de tes sources. Tu as le fichier et la ligne de l'erreur ainsi que l'explication de l'erreur, il ne te reste donc qu'à regarder la ligne en question et de corriger le tout .

    Pour en revenir à ton Makefile, plusieurs choses utiles :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    CC=gcc #CC pour Compilateur C, tu déclares une variable qui vaudra gcc (on utilise CXX pour le C++).
    $(CC) # vaut alors gcc
    CFLAGS="-W -Wall -ansi -pedantic" # options pour le compilateur
    #$(CFLAGS)
    LDFLAGS="-lm" # options pour l'édition des liens
     
    %.o : %.h %.c # pour construire tout ce qui se termine par .o, on a besoin de son .h et de son .c : Foo.o a besoin de Foo.h et de Foo.c
     
    #$@ est le nom de la cible :
    toto.o : toto.h toto.c
             gcc $@
    Ici $@ vaudra "toto.o"
     
    #$^ est la liste des dépendances :
    toto.o : toto.h toto.c titi.h
            gcc $^
    #$^ vaudra alors toto.h toto.c titi.h
     
    # On utilise aussi très souvent une règle :
    clean:
    	rm -rf *.o
    # Pour supprimer tous les fichiers .o directement pour tout recompiler en cas de problèmes.
     
    #Comme clean n'est pas un fichier, on va devoir utiliser :
    .PHONY: clean
    # Pour indiquer que la règle clean doit être exécuté à chaque appel de "make clean" même si un fichier clean existe.
     
    #On a aussi ceci :
    SRC= $(wildcard *.c)
    OBJ= $(SRC:.c=.o)
    #Il va mettre dans SRC tous les noms des fichiers C.
    #Et dans OBJ, il va mettre chaque élément de SRC en remplaçant le .c par .o.
    Au final, ton Makefile devrait ressemble à quelque chose comme :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    CC=gcc
    CFLAGS="-W -Wall -ansi -pedantic"
    LDFLAGS="-lm"
    EXE=MonProgramme
     
    SRC= $(wildcard *.c)
    OBJ= $(SRC:.c=.o)
     
    .PHONY: clean
     
    all : $(EXE)
           # tu peux aussi rajouter ./$(EXE) si tu veux lancer ton programme après compilation.
     
    $(EXE): $(OBJ)
    	$(CC) -o $@ $^ $(LDFLAGS)
     
    panorama.o: panorama.c # Cas particulier, car il a pas de fichier .h associé
           $(CC) -o $@ $^ $(CFLAGS)
     
    %.o : %.c %.h
           $(CC) -o $@ $^ $(CFLAGS)
     
    clean:
    	rm -rf *.o
    Voilà, ce doit être encore un peu compliqué/obscur pour toi, tu n'es pas obligé d'utiliser ceci dans un Makefile, mais je te conseille tout de même d'essayer de comprendre cela.

    L'avantage ici c'est :
    - pouvoir modifier les options de compilation sans devoir les copier/coller 40 fois ;
    - éviter d'avoir deux lignes pour chaque fichiers .c (ce qui peut très vite devenir barbant) ;
    - tu as presque juste à le copier/coller quand tu veux créer un nouveau projet .

    Enfin bref, si tu veux plus de détails, tu peux aussi aller regarder ici :
    http://gl.developpez.com/tutoriel/outil/makefile/

  8. #8
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine et Marne (Île de France)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2013
    Messages : 7
    Points : 0
    Points
    0
    Par défaut
    A premier vue tout va bien et les erreurs viennent de ton code C et pas le makefile

Discussions similaires

  1. [Makefile] : Difficulte avec if/else
    Par samiblide dans le forum Systèmes de compilation
    Réponses: 2
    Dernier message: 20/09/2007, 22h33
  2. Difficulté à construire une requête
    Par coolcpu dans le forum Langage SQL
    Réponses: 6
    Dernier message: 08/10/2003, 00h43
  3. Réponses: 10
    Dernier message: 22/09/2003, 21h58
  4. Difficultés pour afficher un pixel à l'écran
    Par Bubonik software dans le forum C
    Réponses: 9
    Dernier message: 17/08/2003, 12h48
  5. Compilation avec un Makefile
    Par Mau dans le forum GTK+ avec C & C++
    Réponses: 3
    Dernier message: 28/02/2003, 11h30

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