Multiple definition de fonctions !

cs_bidules Messages postés 48 Date d'inscription samedi 31 mars 2001 Statut Membre Dernière intervention 11 avril 2004 - 4 avril 2002 à 20:59
cs_bidules Messages postés 48 Date d'inscription samedi 31 mars 2001 Statut Membre Dernière intervention 11 avril 2004 - 4 avril 2002 à 22:48
bonjour,
lorsque je compile j'ai plein d'erreur me disant qu'il ya des multiple definitions dans mes fichiers objets :

ds tou les fichier .h il y a au debut le #ifndef _FICHIER_H_
#define _FICHIER_H_
ET #endif a la fin
j'ai 3 classes : Matrice :
ds Matrice.h il y a #include"graphique.h"
ds MatriceFonct.cpp il y a #include"Matrice.h"

TabSucc :
ds .h il y a aussi graphique.h
ds cpp il y a TabSucc.h

Goriente :
ds.h il y a Matrice.h et TabSucc.h
ds cpp : Goriente.h

j'ai compiler les fichiers cpp avec g++ -c et il n'y a pas eu d'erreur
Par contre qd je compile le tout :
g++ -o monprog monprog.cpp MatriceFonct.o TabSuccFonct.o GorienteFonct.o

voila : le resulta
[root@jojo projetSD]# g++ -o projet23 projet23.cpp GorienteFonct.o MatriceFonct.o TabSuccFonct.o -lcurses
GorienteFonct.o: In function `LigneH(int, int, int)':
GorienteFonct.o(.text+0x0): multiple definition of `LigneH(int, int, int)'
/tmp/ccjCzXM6.o(.text+0x0): first defined here
GorienteFonct.o: In function `LigneV(int, int, int)':
GorienteFonct.o(.text+0x80): multiple definition of `LigneV(int, int, int)'
/tmp/ccjCzXM6.o(.text+0x80): first defined here
GorienteFonct.o: In function `ConstruireEcran(void)':
GorienteFonct.o(.text+0x104): multiple definition of `ConstruireEcran(void)'
/tmp/ccjCzXM6.o(.text+0x104): first defined here
GorienteFonct.o: In function `Retablissement(void)':
GorienteFonct.o(.text+0x114): multiple definition of `Retablissement(void)'
/tmp/ccjCzXM6.o(.text+0x114): first defined here
MatriceFonct.o: In function `LigneH(int, int, int)':
MatriceFonct.o(.text+0x0): multiple definition of `LigneH(int, int, int)'
/tmp/ccjCzXM6.o(.text+0x0): first defined here
MatriceFonct.o: In function `LigneV(int, int, int)':
MatriceFonct.o(.text+0x80): multiple definition of `LigneV(int, int, int)'
/tmp/ccjCzXM6.o(.text+0x80): first defined here
MatriceFonct.o: In function `ConstruireEcran(void)':
MatriceFonct.o(.text+0x104): multiple definition of `ConstruireEcran(void)'
/tmp/ccjCzXM6.o(.text+0x104): first defined here
MatriceFonct.o: In function `Retablissement(void)':
MatriceFonct.o(.text+0x114): multiple definition of `Retablissement(void)'
/tmp/ccjCzXM6.o(.text+0x114): first defined here
TabSuccFonct.o: In function `LigneH(int, int, int)':
TabSuccFonct.o(.text+0x0): multiple definition of `LigneH(int, int, int)'
/tmp/ccjCzXM6.o(.text+0x0): first defined here
TabSuccFonct.o: In function `LigneV(int, int, int)':
TabSuccFonct.o(.text+0x80): multiple definition of `LigneV(int, int, int)'
/tmp/ccjCzXM6.o(.text+0x80): first defined here
TabSuccFonct.o: In function `ConstruireEcran(void)':
TabSuccFonct.o(.text+0x104): multiple definition of `ConstruireEcran(void)'
/tmp/ccjCzXM6.o(.text+0x104): first defined here
TabSuccFonct.o: In function `Retablissement(void)':
TabSuccFonct.o(.text+0x114): multiple definition of `Retablissement(void)'
/tmp/ccjCzXM6.o(.text+0x114): first defined here
collect2: ld returned 1 exit status

help me please.

2 réponses

cs_jpeg Messages postés 40 Date d'inscription lundi 17 décembre 2001 Statut Membre Dernière intervention 25 février 2004 1
4 avril 2002 à 21:50
Est ce qu'il n'y aurait pas (par hasard) l'implémentation des fonctions citées (LigneV,ConstruireEcran ...) dans ton fichier graphique.h ?
Si c'est le cas, l'implémentation est compilée dans chaque module '.o' (le fichier est inclus directement ou indirectement) et à l'édition des liens ça merde (comme le montrent tes messages d'erreurs) à cause de la redondance ...
Dans de telles conditions, il te faudrait séparer les définitions (dans un graphique.h) de l'implémentation (dans un graphique.cpp) et de générer le .o correspondant avant de faire l'édition des liens ...
Si ce n'est pas le cas, donne moi d'autres précisions ...
0
cs_bidules Messages postés 48 Date d'inscription samedi 31 mars 2001 Statut Membre Dernière intervention 11 avril 2004
4 avril 2002 à 22:48
c tout a fais ca toutes les fonctions citée (ligneV...) se trouve dans graphique.h.
Donc d'apres ce que tu as dit il faudrais que je declare les fonctions ds graphique.h et les definissent ds graphique.cpp,est ce cela? Car si g bien compris lorsque je compile les cpp a chaque fois les fonctions contenus ds graphique.h sont implementer et donc lors de l'edition de liens le compilateur ne c pas quelle definition prendre.Oui si c bien cela je comprend ce qui se passe(je n'est pas beaucoup d'experience ds le domaine de la compilation alors j'essaye de comprendre un peu).
Merci de ton aide.
0
Rejoignez-nous