проблема с makefile, без ссылок

У меня есть два класса: EtatTrafic и EtatTraficTest.

Это мой make-файл:

#Makefile
CXX = g++
LDLIBS = -lcppunit

# a modifier en fonction des cas
OBJS = EtatTrafic.o EtatTraficTest.o

all : TestUnitaire

TestUnitaire: $(OBJS)
$(CXX) $^ -o $@ $(LDFLAGS) $(LDLIBS)

#création des objets
%.o : %.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ -c $<# a modifier en fonction des cas
EtatTrafic.o: EtatTrafic.hpp
EtatTraficTest.o: EtatTrafic.hpp EtatTraficTest.hpp

clean:
rm *.o $(EXEC)

Когда я пытаюсь скомпилировать, я получаю некоторые ошибки, такие как:

EtatTraficTest.o: In function `EtatTraficTest::testConstructeur()':
EtatTraficTest.cpp:(.text+0xab): undefined reference to `EtatTrafic::EtatTrafic(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
EtatTraficTest.cpp:(.text+0xeb): undefined reference to `EtatTrafic::EtatTrafic(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)'
EtatTraficTest.cpp:(.text+0x169): undefined reference to `EtatTrafic::getNbVoitures() const'
EtatTraficTest.cpp:(.text+0x256): undefined reference to `EtatTrafic::getNbPietons() const'

Кажется, что нет никакой связи между моими классами …

Если хотите, это .hpp и .cpp EtatTrafic:

//EtatTrafic.hpp
#ifndef ETATTRAFIC_HPP_
#define ETATTRAFIC_HPP_using namespace std;

/**
* @class EtatTrafic
* @brief Gestion des etats du trafic
* @author Fasy
* @author Pothier
* @author Duval
* @author Lupascu
* @author Mira
* @version 1.0
* @date avril 2013
*/
class EtatTrafic {

private :
unsigned int nbPietons;
unsigned int nbVoitures;
unsigned int nbCamions;
unsigned int nbMotos;
unsigned int nbVelos;
unsigned int nbAccident;

public :

/**
* @fn EtatTrafic(unsigned int nbPietons,unsigned int nbVoitures,unsigned int nbCamions,unsigned int nbMotos, unsigned int nbVelos)
* @brief Constructeur paramétré
* @param nbPietons : nombre de pietons presents dans la ville
* @param nbVoitures : nombre de voitures presentes dans la ville
* @param nbCamions : nombre de camions presents dans la ville
* @param nbMotos :     nombre de motos presents dans la ville
* @param nbVelos : nombre de velos presents dans la ville
*/
EtatTrafic(unsigned int nbPietons,unsigned int nbVoitures,unsigned int nbCamions,unsigned int nbMotos, unsigned int nbVelos);

/**
* @fn unsigned int calculNbVehicules()
* @brief calcul du nombre total de vehicules existants
*/
unsigned int calculNbVehicules();
/**
* @fn unsigned int getNbAccidents()
* @brief renvoie le nombre d'accidents
*/
unsigned int getNbAccidents();

/**
* @fn unsigned int setNbAccidents()
* @brief change le nombre d'accidents
*/
unsigned int setNbAccidents();

/**
* @fn void setNbVoitures(unsigned int nbVt)
* @brief changer le nombre de voitures dans la ville
* @param nbVt :le nouveau nombre de voitures
*/
void setNbVoitures(unsigned int nbVt);
/**
* @fn void setNbPietons(unsigned int nbP)
* @brief changer le nombre de pietons dans la ville
* @param nbVt :le nouveau nombre de pietons
*/
void setNbPietons(unsigned int nbP);
/**
* @fn void setNbCamions(unsigned int nbC)
* @brief changer le nombre de camions dans la ville
* @param nbVt :le nouveau nombre de camions
*/
void setNbCamions(unsigned int nbC);
/**
* @fn void setNbVelos(unsigned int nbVl)
* @brief changer le nombre de Velos dans la ville
* @param nbVt :le nouveau nombre de velos
*/
void setNbVelos(unsigned int nbM);

/**
* @fn void setNbMotos(unsigned int nbM)
* @brief changer le nombre de motos dans la ville
* @param nbM :le nouveau nombre de motos
*/
void setNbMotos(unsigned int nbM);
/**
* @fn unsigned int getNbVoitures() const
* @brief Obtenir le nobre de voitures de la ville
*/
unsigned int getNbVoitures() const;
/**
* @fn unsigned int getNbPietons() const
* @brief Obtenir le nobre de pietons de la ville
*/
unsigned int getNbPietons() const;
/**
* @fn unsigned int getNbCamions() const
* @brief Obtenir le nobre de camions de la ville
*/

unsigned int getNbCamions() const;
/**
* @fn unsigned int getNbVelos() const
* @brief Obtenir le nobre de velos de la ville
*/
unsigned int getNbVelos() const;

/**
* @fn unsigned int getNbMotos() const
* @brief Obtenir le nobre de motos de la ville
*/
unsigned int getNbMotos() const;};#endif /* ETATTRAFIC_HPP_ */

// EtatTrafic.cpp

#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>int main(int argc, char* argv[])
{
// Get the top level suite from the registry
// déclaration d'une suite de tests
CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();

// Adds the test to the list of test to run
// chargement de la suite de tests présentée dans la classe ...Test.hpp
CppUnit::TextUi::TestRunner runner;
runner.addTest( suite );

// Change the default outputter to a compiler error format outputter
// transformation du format de sortie
runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
std::cerr ) );
// Run the tests.
// lancement des tests
bool wasSucessful = runner.run();

// Return error code 1 if the one of test failed.
// retour
return wasSucessful ? 0 : 1;
}

Это .hpp и .cpp EtatTraficTest:

//EtatTrafictest.chpp
#ifndef ETATTRAFICTEST_H
#define ETATTRAFICTEST_H

//ligne a recopier
#include <cppunit/extensions/HelperMacros.h>

class EtatTraficTest : public CppUnit::TestFixture
{
//ligen a recopier (change le "MoneyTest")
CPPUNIT_TEST_SUITE( EtatTraficTest );

//ordre d'execution des tests
CPPUNIT_TEST( testConstructeur );
CPPUNIT_TEST( testCalculNbVehicules );

//ligen a recopier
CPPUNIT_TEST_SUITE_END();

public:

//déclaration des méthodes tests
void testConstructeur();
void testCalculNbVehicules();
void testCalculNbAccident();

};

#endif

// EtatTraficTest.cpp
//include à appliquer sur nos classes
#include "EtatTraficTest.hpp"#include "EtatTrafic.hpp"
//ligne à recopier tel quel
// Registers the fixture into the 'registry'
CPPUNIT_TEST_SUITE_REGISTRATION( EtatTraficTest );

//déclaration des méthodes tests
// attention ces méthodes ne contiennent pas de paramètres !
void  EtatTraficTest::testConstructeur()
{
// Set up
// déclation des objets qui vont etre utilisés
const unsigned int nbPietons0 =0;
const unsigned int nbPietons1 =3;
//const unsigned int nbPietons2 = ;
const unsigned int nbVoitures0 =0;
const unsigned int nbVoitures1 =2;
//const unsigned int nbVoitures2 = ;
const unsigned int nbCamions0 =0;
const unsigned int nbCamions1 =5;
//const unsigned int nbCamions2 = ;
const unsigned int nbMotos0 =0;
const unsigned int nbMotos1 =6;
//const unsigned int nbMotos2 = ;
const unsigned int nbVelos0 =0;
const unsigned int nbVelos1 =4;
//const unsigned int nbVelos2 = ;// Process
// appel de la méthode à tester (ici il s'agit du constructeur)

//cas limite
EtatTrafic etat0(nbPietons0, nbVoitures0, nbCamions0, nbMotos0, nbVelos0);

//cas normal
EtatTrafic etat1(nbPietons1, nbVoitures1, nbCamions1, nbMotos1, nbVelos1);

//cas d'erreur
//EtatTrafic etat2(nbPietons2, nbVoitures2, nbCamions2, nbMotos2, nbVelos2);// Check
// lancement des tests unitaires

CPPUNIT_ASSERT_EQUAL( nbVoitures0, etat0.getNbVoitures() );
CPPUNIT_ASSERT_EQUAL( nbPietons0, etat0.getNbPietons() );
CPPUNIT_ASSERT_EQUAL( nbCamions0, etat0.getNbCamions() );
CPPUNIT_ASSERT_EQUAL( nbMotos0, etat0.getNbMotos() );
CPPUNIT_ASSERT_EQUAL( nbVelos0, etat0.getNbVelos() );

CPPUNIT_ASSERT_EQUAL( nbVoitures1, etat1.getNbVoitures() );
CPPUNIT_ASSERT_EQUAL( nbPietons1, etat1.getNbPietons() );
CPPUNIT_ASSERT_EQUAL( nbCamions1, etat1.getNbCamions() );
CPPUNIT_ASSERT_EQUAL( nbMotos1, etat1.getNbMotos() );
CPPUNIT_ASSERT_EQUAL( nbVelos1, etat1.getNbVelos() );

/*CPPUNIT_ASSERT_EQUAL( nbVoitures2, etat2.getNbVoitures() );
CPPUNIT_ASSERT_EQUAL( nbPietons2, etat2.getNbPietons() );
CPPUNIT_ASSERT_EQUAL( nbCamions2, etat2.getNbCamions() );
CPPUNIT_ASSERT_EQUAL( nbMotos2, etat2.getNbMotos() );
CPPUNIT_ASSERT_EQUAL( nbVelos2, etat2.getNbVelos() );*/

}
void  EtatTraficTest::testCalculNbVehicules()
{
// Set up
// déclation des objets qui vont etre utilisés
const unsigned int nbPietons0 =0;
const unsigned int nbPietons1 =3;
//const unsigned int nbPietons2 = ;
const unsigned int nbVoitures0 =0;
const unsigned int nbVoitures1 =2;
//const unsigned int nbVoitures2 = ;
const unsigned int nbCamions0 =0;
const unsigned int nbCamions1 =5;
//const unsigned int nbCamions2 = ;
const unsigned int nbMotos0 =0;
const unsigned int nbMotos1 =6;
//const unsigned int nbMotos2 = ;
const unsigned int nbVelos0 =0;
const unsigned int nbVelos1 =4;
//const unsigned int nbVelos2 = ;

const unsigned int nbVehiculeTotale0= nbPietons0+nbVoitures0+nbCamions0+nbMotos0+nbVelos0;
const unsigned int nbVehiculeTotale1= nbPietons1+nbVoitures1+nbCamions1+nbMotos1+nbVelos1;
//const unsigned int nbVehiculeTotale2= nbPietons2+nbVoitures2+nbCamions2+nbMotos2+nbVelos2;
// Process
// appel de la méthode à tester (ici il s'agit du constructeur)

//cas limite
EtatTrafic etat0(nbPietons0, nbVoitures0, nbCamions0, nbMotos0, nbVelos0);

//cas normal
EtatTrafic etat1(nbPietons1, nbVoitures1, nbCamions1, nbMotos1, nbVelos1);

//cas d'erreur
//EtatTrafic etat2(nbPietons2, nbVoitures2, nbCamions2, nbMotos2, nbVelos2);

// Check
// lancement des tests unitaires

CPPUNIT_ASSERT_EQUAL(nbVehiculeTotale0, etat0.calculNbVehicules() );
CPPUNIT_ASSERT_EQUAL( nbVehiculeTotale1, etat1.calculNbVehicules() );
//CPPUNIT_ASSERT_EQUAL( nbVehiculeTotale2, etat2.calculNbVehicules() );

}

0

Решение

Ваш компилятор жалуется, что не может найти определения для членов EtatTrafic, такие как EtatTrafic::getNbVoitures(), Этот метод объявленный в EtatTrafic.hpp (файл говорит, что метод существует), но это не так определенный в любом из файлов, которые вы показали нам (ни один файл не говорит, что метод делает).

По соглашению, определение методов EtatTrafic должен быть в EtatTrafic.cpp, но это не так. Если они не существуют, вы должны написать их; если они существуют в каком-то другом файле, вы должны либо переместить их в EtatTrafic.cppили добавьте соответствующий объектный файл в переменную makefile OBJS,

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector