Erreur de compilation C++ avec Makefile
Bonjour
J'ai réalisé à l'aide du tuto du site un makefile sommaire et ça ne fonctionne pas alors que la commande g++ -o produit.out *.cpp elle fonctionne (le programme aussi).
Voici l'erreur que j'obtiens à la compilation :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| make
g++ -o main.o -c main.cpp
g++ -o liste.o -c liste.cpp
g++ -o menu.o -c menu.cpp
g++ -o prod.o -c prod.cpp
g++ -o produit main.o liste.o menu.o
liste.o: dans la fonction « affiche(liste) »:
liste.cpp:(.text+0x157): référence indéfinie vers « afficher_produit(produit) »
menu.o: dans la fonction « traiter_choix(liste&, int)»:
menu.cpp:(.text+0xae): référence indéfinie vers « saisir_produit(produit&) »
collect2: ld a retourné 1 code d'état d'exécution
make: *** [produit] Erreur 1 |
Voici mon fichier makefile qui est très très basique :P:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| all: produit
produit: main.o liste.o menu.o prod.o
g++ -o produit main.o liste.o menu.o
main.o: main.cpp liste.h menu.h
g++ -o main.o -c main.cpp
liste.o: liste.cpp prod.h
g++ -o liste.o -c liste.cpp
menu.o: menu.cpp liste.h
g++ -o menu.o -c menu.cpp
prod.o: prod.cpp
g++ -o prod.o -c prod.cpp
clean:
rm -rf *.o
mrproper: clean
rm -rf produit |
Voici les fichiers avec le codes sources (qui se trouvent tous dans le même rep):
liste.cpp
Code:
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
| #include <iostream>
#include "liste.h"
using namespace std;
void init_liste(liste &l) {
l.nb = 0;
}
int ajoute(liste &l, produit p) {
int r;
if(l.nb == liste_nb_max)
r = liste_pleine;
else {
r = 0;
l.t[l.nb] = p;
++l.nb;
}
return r;
}
void affiche(liste l) {
int i;
if(l.nb == 0)
cout << "Liste vide" << endl;
else
for(i=0; i<l.nb; ++i)
afficher_produit(l.t[i]);
} |
liste.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #ifndef LISTE_H
#define LISTE_H
#include "prod.h"
const int liste_pleine = -1;
const int liste_nb_max = 100;
struct liste {
int nb;
produit t[liste_nb_max];
};
void init_liste(liste &l);
int ajoute(liste &l, produit p);
void affiche(liste l);
#endif |
main.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11
| #include "liste.h"
#include "menu.h"
int main() {
liste l;
init_liste(l);
menu(l);
return 0;
} |
menu.cpp
Code:
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
| #include <iostream>
#include "menu.h"
using namespace std;
int choix() {
int i;
cout << "1. Ajouter un produit" << endl;
cout << "2. Afficher la liste des produits" << endl;
cout << "3. Supprimer un produit" << endl;
cout << "4. Acheter un produit" << endl;
cout << "5. Vendre un produit" << endl;
cout << "6. Quitter" << endl;
cin >>i;
return i;
}
void menu(liste &l) {
bool fini;
int i;
do {
i = choix();
fini = traiter_choix(l, i);
}
while(fini == false);
}
bool traiter_choix(liste &l, int choix) {
produit p;
int r;
bool fini = false;
switch(choix) {
case 1:
saisir_produit(p);
r = ajoute(l, p);
if(r == liste_pleine)
cout << "La liste est pleine" << endl;
break;
case 2:
affiche(l);
break;
case 3:
//supprimer produit
break;
case 4:
//acheter
break;
case 5:
//vendre
break;
case 6:
fini = true;
break;
}
return fini;
} |
menu.h
Code:
1 2 3 4 5 6 7 8 9
| #ifndef MENU_H
#define MENU_H
#include "liste.h"
void menu(liste &l);
int choix();
bool traiter_choix(liste &l, int choix);
#endif |
prod.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| #include <iostream>
#include "prod.h"
using namespace std;
void saisir_produit(produit &p) {
cout << "Entrez le code produit : ";
cin >> p.code;
cout << "Entrez l'intitulé : ";
cin >> p.intitule;
p.quantite_stock = 0;
}
void afficher_produit(produit p) {
cout << p.code << " " << p.intitule << " : " << p.quantite_stock << endl;
} |
prod.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| #ifndef PROD_H
#define PROD_H
struct produit {
char code[9];
char intitule[99];
int quantite_stock;
};
void saisir_produit(produit &p);
void afficher_produit(produit p);
#endif |
Voilà donc si quelqu'un peut m'indiquer où se trouve mon erreur, je suis preneur :D