bonjour à tous,
je ne comprend pas ce qui ce passe:
voici les fichiers
quand je fais:
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 //environnement.hpp #ifndef ENVIRONNEMENT_HPP #define ENVIRONNEMENT_HPP #include <iostream> #include <fstream> using namespace std; #define TAILLE_TAMPON 4096 #define SENTINELLE 2047 #define TAILLE_DEMI_TAMPON 2047 typedef enum {C,FDF} ULEX; ifstream source; ULEX symbole; char tampon[TAILLE_TAMPON]; int debutlex,enavant=0,numligne=1; char* valex; void charger1(); ULEX analex(); void charger2(); void reculer(); void copier_fichier(); void fichier(); void accepter(ULEX lex); void emettre(char* valex); #endif //principal.cpp #include "environnement.hpp" int main(int argc,char **argv){ if(argc!=2){ cout<<"usage:"<<endl<<"compilo <fichier>"<<endl; } else{ source.open(argv[1],ios_base::in); tampon[SENTINELLE]=tampon[TAILLE_TAMPON-1]=EOF; if(source.is_open()){ charger1(); symbole=analex(); copier_fichier(); cout<<"terminé"<<endl; source.close(); } else{ cout<<"erreur à l'ouverture du fichier \""<<argv[1]<<"\""<<endl; return 1; } } return 0; } //syntaxique.cpp #include "environnement.hpp" void copier_fichier(){ fichier(); accepter(FDF); emettre("\n"); } void fichier(){ while(symbole!=FDF){ emettre(valex); accepter(C); } } void accepter(ULEX lex){ if(symbole==lex) symbole=analex(); else{ cerr<<endl<<"le symbole courrant "<<symbole<<" ne corespond pas au lexème attendu "<<lex<<" à la ligne "<<numligne<<endl; symbole=FDF; } } //lexical.cpp #include "environnement.hpp" ULEX analex(){ char c; while(1){ c=tampon[enavant]; switch(c){ case EOF: if(enavant==SENTINELLE){ charger2(); enavant=SENTINELLE+1; } else if(enavant==TAILLE_TAMPON-1){ charger1(); enavant=0; } else return FDF; break; case '\n': numligne++; case '\t':case ' ': enavant++; break; default: valex=new char[2]; *valex=tampon[enavant]; *(valex+1)='\0'; enavant++; return C; } } } void charger1(){ int i; for(i=0;i<SENTINELLE;i++) tampon[i]='\0'; source.read(tampon,TAILLE_DEMI_TAMPON); if(source.tellg()==-1){ for(i=SENTINELLE;i>0 && tampon[i-1]=='\0';i--) ; tampon[i]=EOF; } } void charger2(){ int i; for(i=SENTINELLE+1;i<TAILLE_TAMPON-1;i++) tampon[i]='\0'; source.read(tampon+SENTINELLE+1,TAILLE_DEMI_TAMPON); if(source.tellg()==-1){ for(i=TAILLE_TAMPON-1;i>SENTINELLE && tampon[i-1]=='\0';i--) ; tampon[i]=EOF; } } void reculer(){ char c; if(enavant==0){ source.seekg(-TAILLE_DEMI_TAMPON,ios::cur); charger2(); enavant=TAILLE_TAMPON-1; } else if(enavant==SENTINELLE+1){ source.seekg(-TAILLE_DEMI_TAMPON,ios::cur); charger1(); enavant=SENTINELLE-1; } else{ enavant--; } } //emeteur.cpp #include "environnement.hpp" void emettre(char* valex){ cout<<valex; }
jusque là, tout va bien.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 g++ -c emeteur.cpp g++ -c lexical.cpp g++ -c principal.cpp g++ -c syntaxique.cpp
Mais l’édition de liens ne fonctionne pas:
quelqu'un a une idée?
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 g++ -o orsay *o lexical.o:(.bss+0x0): multiple definition of `source' emeteur.o:(.bss+0x0): first defined here lexical.o:(.bss+0x118): multiple definition of `symbole' emeteur.o:(.bss+0x118): first defined here lexical.o:(.bss+0x120): multiple definition of `tampon' emeteur.o:(.bss+0x120): first defined here lexical.o:(.bss+0x1120): multiple definition of `debutlex' emeteur.o:(.bss+0x1120): first defined here lexical.o:(.bss+0x1124): multiple definition of `enavant' emeteur.o:(.bss+0x1124): first defined here lexical.o:(.data+0x0): multiple definition of `numligne' emeteur.o:(.data+0x0): first defined here lexical.o:(.bss+0x1128): multiple definition of `valex' emeteur.o:(.bss+0x1128): first defined here principal.o:(.bss+0x0): multiple definition of `source' emeteur.o:(.bss+0x0): first defined here principal.o:(.bss+0x118): multiple definition of `symbole' emeteur.o:(.bss+0x118): first defined here principal.o:(.bss+0x120): multiple definition of `tampon' emeteur.o:(.bss+0x120): first defined here principal.o:(.bss+0x1120): multiple definition of `debutlex' emeteur.o:(.bss+0x1120): first defined here principal.o:(.bss+0x1124): multiple definition of `enavant' emeteur.o:(.bss+0x1124): first defined here principal.o:(.data+0x0): multiple definition of `numligne' emeteur.o:(.data+0x0): first defined here principal.o:(.bss+0x1128): multiple definition of `valex' emeteur.o:(.bss+0x1128): first defined here syntaxique.o:(.bss+0x0): multiple definition of `source' emeteur.o:(.bss+0x0): first defined here syntaxique.o:(.bss+0x118): multiple definition of `symbole' emeteur.o:(.bss+0x118): first defined here syntaxique.o:(.bss+0x120): multiple definition of `tampon' emeteur.o:(.bss+0x120): first defined here syntaxique.o:(.bss+0x1120): multiple definition of `debutlex' emeteur.o:(.bss+0x1120): first defined here syntaxique.o:(.bss+0x1124): multiple definition of `enavant' emeteur.o:(.bss+0x1124): first defined here syntaxique.o:(.data+0x0): multiple definition of `numligne' emeteur.o:(.data+0x0): first defined here syntaxique.o:(.bss+0x1128): multiple definition of `valex' emeteur.o:(.bss+0x1128): first defined here collect2: ld returned 1 exit status
Partager