Bonjour,
j'ai fais un petit programme pour comparer lesm anières de passer une variable, le programme fonctionne bien si je compile avec cette ligne :
Mais si je change par :
Code : Sélectionner tout - Visualiser dans une fenêtre à part g++ -o out main.cpp
J'ai vraiment beaucoup d'erreurs du genre :
Code : Sélectionner tout - Visualiser dans une fenêtre à part g++ -o -wall out main.cpp
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 out: In function `_start': /build/buildd/glibc-2.9/csu/../sysdeps/i386/elf/start.S:65: multiple definition of `_start' /usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o:/build/buildd/glibc-2.9/csu/../sysdeps/i386/elf/start.S:65: first defined here out:(.rodata+0x0): multiple definition of `_fp_hw' /usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o:(.rodata+0x0): first defined here out: In function `_fini': /build/buildd/glibc-2.9/csu/../sysdeps/generic/initfini.c:109: multiple definition of `_fini' /usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crti.o:/build/buildd/glibc-2.9/csu/../sysdeps/generic/initfini.c:109: first defined here out:(.rodata+0x4): multiple definition of `_IO_stdin_used' /usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here out: In function `__data_start': (.data+0x0): multiple definition of `__data_start' /usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crt1.o:(.data+0x0): first defined here out: In function `__data_start': (.data+0x4): multiple definition of `__dso_handle' /usr/lib/gcc/i486-linux-gnu/4.3.3/crtbegin.o:(.data+0x0): first defined here out: In function `_init': /build/buildd/glibc-2.9/build-tree/i386-libc/csu/crti.S:15: multiple definition of `_init' /usr/lib/gcc/i486-linux-gnu/4.3.3/../../../../lib/crti.o:/build/buildd/glibc-2.9/build-tree/i386-libc/csu/crti.S:15: first defined here /tmp/cccQWNZJ.o: In function `powc': main.cpp:(.text+0x0): multiple definition of `powc' out:(.text+0xb4): first defined here /tmp/cccQWNZJ.o: In function `powref(int, int)': main.cpp:(.text+0x70): multiple definition of `powref(int, int)' out:(.text+0x124): first defined here /tmp/cccQWNZJ.o: In function `powretour(int, int, long double&)': main.cpp:(.text+0xde): multiple definition of `powretour(int, int, long double&)' out:(.text+0x192): first defined here /tmp/cccQWNZJ.o: In function `main': main.cpp:(.text+0x1a0): multiple definition of `main' out:(.text+0x254): first defined here /usr/lib/gcc/i486-linux-gnu/4.3.3/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__' out:(.dtors+0x4): first defined here /usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored. /usr/bin/ld: error in out(.eh_frame); no .eh_frame_hdr table will be created. collect2: ld a retourné 1 code d'état d'exécution
Pour info, voici mon fichier principal :
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 extern "C" { #include "exo1.c" } using namespace std; #include "powcpp.cpp" #include<iostream> int main(){ int n,m; long double res,res2,res3; cout << "Entrez la valeur puis l'exposant :" << endl; cin >> n; cin >> m; res = powc(n,m); res2 = powref(n,m); powretour(n,m,res3); cout << "Resultat powc : " << res << endl << "Resultat powref : " << res2 <<endl << "Resultat powretour : " << res3 << endl; return 0; }
et les deux autres
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 long double powc(int val, int exp) { long double res; double pas; int i; if (exp < 0){ pas = (double) 1/val; exp = -exp; } else { pas = val; } res = 1; for (i=0;i<exp;i++) { res *= pas; } return res; }
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 long double &powref(int val, int exp) { static long double res; double pas; int i; if (exp < 0){ pas = (double) 1/val; exp = -exp; } else { pas = val; } res = 1; for (i=0;i<exp;i++) { res *= pas; } return res; } void powretour(int val, int exp,long double &result) { double pas; int i; if (exp < 0){ pas = (double) 1/val; exp = -exp; } else { pas = val; } result = 1; for (i=0;i<exp;i++) { result *= pas; } }
Merci d'avance pour votre aide.
Partager