Compiler du c++ avec gcc ou g++, sous linux !

Fermé
Pmastery Messages postés 84 Date d'inscription mercredi 27 février 2008 Statut Membre Dernière intervention 2 décembre 2011 - 20 déc. 2009 à 20:35
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 - 20 déc. 2009 à 22:46
Bonjour,

pour comencer jai trois fichier

crypto.h, main.cpp et crypto.cpp

je lance

$ gcc -c crypto.cpp
In file included from crypto.cpp:2:
crypto.h:15: warning: ‘int main(int)’ takes only zero or two arguments
crypto.cpp: In function ‘void aide()’:
crypto.cpp:106: warning: deprecated conversion from string constant to ‘char*’
crypto.cpp: In function ‘void apropos()’:
crypto.cpp:116: warning: deprecated conversion from string constant to ‘char*’

$ gcc -c main.cpp
In file included from main.cpp:1:
crypto.h:15: warning: ‘int main(int)’ takes only zero or two arguments
main.cpp:3: warning: ‘int main(int)’ takes only zero or two arguments
main.cpp: In function ‘int main(int)’:
main.cpp:22: warning: deprecated conversion from string constant to ‘char*’
main.cpp:36: warning: deprecated conversion from string constant to ‘char*’


$ gcc -o crypt main.o crypto.o
main.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
crypto.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status


voila les commande sont t'elle bonne ?
suite a la derniere commande la compilation ne me donner pas de fichier executable?

merci a tous !

Pmastery
A voir également:

3 réponses

KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
20 déc. 2009 à 22:12
Apparemment tu fais int main(int)
Les syntaxes correctes sont int main(void), int main(int argc, char*argv[]), int main(int argc, char*argv[], char* arge[])

Sinon pour la compilation c'est : gcc fichier.cpp -o nomApresExecution

En général collect2 : ld returned 1 exit status, c'est quand tu compiles un programme alors qu'il est en cours d'exécution.
0
Pmastery Messages postés 84 Date d'inscription mercredi 27 février 2008 Statut Membre Dernière intervention 2 décembre 2011 2
20 déc. 2009 à 22:36
merci !

en effet, mais j'ai bien un
int main(int argc)

je ne vois pas comment le prog pourrait etre en cour d'execution quand j'arrive meme pas a le compiler !!
voici le code du main :

#include "crypto.h"



int main(int argc)

{

int choix, cle;

char cryp_c[256], cryp_d[256];



if(argc)

menu();



do{

printf("\nChoisissez une operation: ");

scanf("%d", &choix);



switch(choix)

{

case 0:

break;



case 1 :

printf("\n\n");

interface("CRYPTAGE");

printf("\nEntrez le chemin exact du fichier a crypter : ");

scanf("%s",cryp_c);

printf("\nEntrez le chemin exact du fichier destination : ");

scanf("%s",cryp_d);

printf("\nEntrez la cle du cryptage : ");

scanf("%d", &cle);

crypt_f(cryp_c, cryp_d, cryptage, cle);

printf("\nCryptage termine, veuillez patienter...!\n");

printf("\nCryptage et enregistrement termines...\n");

break;



case 2 :

printf("\n\n");

interface("DECRYPTAGE");

printf("\nEntrez le chemin exact du fichier a decrypter : ");

scanf("%s",cryp_c);

printf("\nEntrez le chemin exact du fichier destination : ");

scanf("%s",cryp_d);

printf("\nEntrez la cle du cryptage : ");

scanf("%d", &cle);

crypt_f(cryp_c, cryp_d, decryptage, cle);

printf("\nDecryptage termine, veuillez patienter...!\n");

printf("\nDecryptage et enregistrement termines...\n");

break;



case 3 :

printf("\n\n");

aide();

printf("\n\n");

next();

break;

case 4 :

printf("\n\n");

apropos();

printf("\n\n");

next();

break;



default:

printf("\nErreur: Mauvaise entree...\n");

break;



}

}

while(choix != 0);



printf("\nFin des operations...\n\n");

fin();



return 0;

}



void next(void)

{

//printf("Appuyer sur une touche pour continuer...");

//char *c;

//scanf("%s", &c);

}


merci de me donner un cop de main !
0
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
20 déc. 2009 à 22:46
int main(int argc) ce n'est pas bon ! Encore moins if(argc) alors qu'on est sûr que argc>=1 !
Pour le collect2 j'ai dit qu'en général c'était ça, ça veut pas dire toujours...

Il serait peut-être plus judicieux de faire case 0: exit(); pour sortir de ta boucle

Pour le reste, les erreurs ne sont pas forcément dans le main. Rregarde en particulier an lignes 106, 116 de crypto.cpp

Et par la suite met des balises de codes pour l'indentation
0