簡體   English   中英

Makefile的麻煩,沒有參考

[英]trouble with makefile, no references

我有兩節課:EtatTrafic和EtatTraficTest。

這是我的makefile:

#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'

看來我的班級之間沒有聯系...

我想要的是EtatTrafic的.hpp和.cpp:

//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;
}

這些是EtatTraficTest的.hpp和.cpp:

//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() );

  }

您的編譯器抱怨它找不到EtatTrafic成員的EtatTrafic ,例如EtatTrafic::getNbVoitures() 該方法在EtatTrafic.hpp聲明 (該文件表明該方法存在),但未在您顯示給我們的任何文件中定義 (沒有文件說明該方法的作用 )。

按照慣例, EtatTrafic方法的EtatTrafic應在EtatTrafic.cpp ,但EtatTrafic.cpp並非如此。 如果它們不存在,則必須編寫它們; 如果它們存在於其他文件中,則必須將它們移至EtatTrafic.cpp ,或將適當的目標文件添加到makefile變量OBJS

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM