make:致命错误:目标命令失败



我目前正在做一个 C++ 项目,但我有一个问题,无法让我进步。 这是我的制作文件:

Test:   Test2.cpp Joueur.o Matricule.o Classement.o 
g++ -o Test2 Test2.cpp Joueur.o Matricule.o Classement.o 
Joueur.o:   Joueur.cxx Joueur.h
g++ Joueur.cxx -c
Matricule.o:    Matricule.cxx Matricule.h
g++ Matricule.cxx -c
Classement.o:   Classement.cxx Classement.h
g++ Classement.cxx -c

我在上一个练习中使用相同的生成文件,但没有分类和预科,它起作用了。 当我使用此make时,它向我显示该消息:

student@solaris11DMSept2015:~/Téléchargements$ make
g++ -o Test2 Test2.cpp Joueur.o Matricule.o Classement.o
Undefined           first referenced
symbol                 in file
Essai3()                            /var/tmp//cc62aqDe.o
Essai4()                            /var/tmp//cc62aqDe.o
Essai2()                            /var/tmp//cc62aqDe.o
ld: fatal: symbol referencing errors
collect2: error: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `Test'

这是测试2的代码.cpp:

#include <stdlib.h>
#include <iostream>
#include <string.h>
#include "Joueur.h"
#include "Matricule.h"
#include "Classement.h"
using namespace std;

int  Menu();
void Essai1();
void Essai2();
void Essai3();
void Essai4();

int main(int argc,char* argv[])
{
bool fini = false;
while(!fini)
{
int choix;
if (argc == 2) { choix = atoi(argv[1]); fini = true; }
else choix = Menu();
switch(choix)
{
case 1 : Essai1(); break;
case 2 : Essai2(); break;
case 3 : Essai3(); break;
case 4 : Essai4(); break;
default : fini = true ; break;
}
}
return 0;
}
//*******************************************************************************************************
int Menu()
{
cout << endl;
cout << "--------------------------------------------------------------------------------------" << endl;
cout << "--- JEU DE TESTS 2 -------------------------------------------------------------------" << endl;
cout << "--------------------------------------------------------------------------------------" << endl;
cout << " 1. Tests de la classe Matricule" << endl;
cout << " 2. Tests de la classe Classement" << endl;
cout << " 3. Tests de la classe Joueur (avec agregations par valeur et par reference)" << endl;
cout << " 4. Tests des variables statiques utiles" << endl;
cout << " 5. Quitter" << endl << endl;
int ch;
cout << "  Choix : ";
cin >> ch; // Faites pas le biess !
return ch;
}
//*******************************************************************************************************
//*** Tests de la classe Matricule **********************************************************************
//*******************************************************************************************************
void Essai1()
{
cout << "(1) ***** Test des constructeurs de Matricule *****" << endl;
{
Matricule m1, m2("01/09/2016",25369), m3(m2);
cout << "Defaut : "; m1.Affiche();
cout << "Initialisation : "; m2.Affiche();
cout << "Copie : "; m3.Affiche();
cout << endl;
}
cout << endl << "(2) **** Test des setters/getters *****" << endl;
{
Matricule m;
cout << "Defaut : "; m.Affiche();
m.setDateInscription("15/10/2012");
m.setNumero(14817);
cout << "Apres setters : "; m.Affiche();
cout << endl << "Date inscription : " << m.getDateInscription() << endl;
cout << "Numero : " << m.getNumero() << endl;
}
}

我是初学者,但我知道这种makefile很简单,但我还没有发现问题。 问题真的在制作文件中吗?

这个问题已经解决了,它不是来自那些代码,问题来自我的类。现在,当我选择"essai3"时,我收到消息"分段错误(核心转储(" 这个问题来自这个类:

#include "Joueur.h"
#include "Classement.h"
#include "Matricule.h"
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std;
Joueur::Joueur(){
nom = new char[20];
prenom = new char[20];
numclub =0;
classement;
matricule;
}
Joueur::Joueur(const char *n,const char *p,const int x){
setNom(n);
setPrenom(p);
setNumClub(x);
}
Joueur::Joueur(const char *n,const char *p,const int x,const Matricule m){
setNom(n);
setPrenom(p);
setNumClub(x);
setMatricule(m);
}
Joueur::Joueur(const Joueur &j)
{   
setNom(j.getNom());
setPrenom(j.getPrenom());
setNumClub(j.getNumClub());                 
}
void Joueur::Affiche(){
cout << "nom :" << getNom() << endl;
cout << "prenom :" << getPrenom() << endl;
cout << "numéro du club:" << getNumClub() << endl;
cout << "numéro matricule: " << matricule.getNumero()<<endl;
cout << "date inscription: " << matricule.getDateInscription()<<endl;
cout << "classement: "<< classement->getLettre()<<classement->getNombre()<<endl;
}
void Joueur::setMatricule(const Matricule m) {
matricule.setNumero(m.getNumero());
matricule.setDateInscription(m.getDateInscription());
}
void Joueur::setClassement(const Classement &c) {
classement = new Classement();
classement->setLettre(c.getLettre());
classement->setNombre(c.getNombre());
}
void Joueur::setNom(const char* n) {
if((strlen(n)+1)<20){
strcpy(nom,n);
return ;
}
else{
return ;
}
}   
void Joueur::setPrenom(const char* p) { 
if((strlen(p)+1)<20){
strcpy(prenom,p);
return ;
}
else{
return ;
}
}
void Joueur::setNumClub(int x){
if(x<0){
return ;
}
else{
numclub = x;
}
}
Matricule Joueur::getMatricule()const
{
return matricule;
}
Classement* Joueur::getClassement()const
{
return classement;
}
char* Joueur::getNom()const
{ 
return nom;
}
char* Joueur::getPrenom()const
{
return prenom;
}
int Joueur::getNumClub()const
{
return numclub;
}
Joueur::~Joueur(){
delete[] nom;
delete[] prenom;
}   

最新更新