Проблема компоновщика Catch2 C ++ - включены неопределенные символы для классов - PullRequest
1 голос
/ 28 февраля 2020

Работа над школьным проектом c ++. Похоже, тестирование catch2 не работает правильно.

У меня есть make-файл, где я компилирую свой проект

CC=clang++
CFLAGS=--std=c++11

objects = Event.o Simulation.o ListItem.o Node.o OrderedItem.o PartArrival.o 
PriorityQueue.o Queue.o PartOne.o PartTwo.o PartZero.o PartialProduct.o 
ProductArrival.o StartAssembly.o StartFinishingAssembly.o EndFinishingAssembly.o 
StartMainAssembly.o EndMainAssembly.o EndAssembly.o Test_PriorityQueue.o
# .. etc .. put a list of your .o files here

# this rule will build A2 as the executable from the object files
all : A2main.o $(objects)
   $(CC) $(CFLAGS) -o A2 $< $(objects)

# this rule will build A2test -- our testfile for the PriorityQueue
all : Test_PriorityQueue.cpp
   clang++ --std=c++11 -o A2test Test_PriorityQueue.cpp

# this rule will build a .o file from a .cpp file.
%.o: %.cpp
   $(CC) -c -o $@ $< $(CFLAGS)

Когда эта строка запускается clang++ --std=c++11 -o A2test Test_PriorityQueue.cpp Я получаю эту ошибку:

Undefined symbols for architecture x86_64:
"Simulation::Simulation()", referenced from:
  ____C_A_T_C_H____T_E_S_T____4() in Test_PriorityQueue-1f17a8.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

Вот код для файл теста - Test_PriorityQueue. cpp:

#define CATCH_CONFIG_MAIN  // This tells Catch to provide a main() - only do 
this in one cpp file
#include "catch.hpp"
#include "Simulation.h"
#include "PartArrival.h"
#include "PriorityQueue.h"
#include <iostream>
using namespace std;

unsigned int Factorial( unsigned int number ) {
  return number <= 1 ? number : Factorial(number-1)*number;
}

TEST_CASE( "Factorials are computed", "[factorial]" ) {
  REQUIRE( Factorial(1) == 1 );
  REQUIRE( Factorial(2) == 2 );
  REQUIRE( Factorial(3) == 6 );
  REQUIRE( Factorial(10) == 3628800 );
}

// debugging test 
TEST_CASE("CATCH TEST"){
  REQUIRE(1 == 1);
}

TEST_CASE("create PQ") {
  cout << "PQ testcase" << endl;  
  Simulation *sim = new Simulation();
  //  PriorityQueue *pQue = new PriorityQueue();
  //  REQUIRE(pQue->getSize() == 0);
 }

Первые несколько тестов выполняются очень хорошо, когда я закомментирую последний "create PQ". Как только я включу, я начинаю получать эти неопределенные ошибки символов. Некоторое время ударился головой об это. Некоторая помощь будет очень признательна!

Редактировать:

Simulation.h

#ifndef START_FILES_SIMULATION_H
#define START_FILES_SIMULATION_H

#pragma once
#include <fstream>
using namespace std;

class PriorityQueue; // Priority Queue
class Queue; // Queue class - provided to you
class Event; // Event - given to you.
class PartZero; // p0
class PartOne; // p1
class PartTwo; // p2
class PartialProduct; // partially assembled product

class Simulation {
private:
    ifstream ifile; // input file to read.
    int simulationTime; // what is the current time of the simulation?
    PriorityQueue *eventList; // priority queue of Events.
    Queue* productQueue; // queue of partially assembled products (for finishing station).
    Queue** partQueues; // *array* of queues of parts for the stations.
    int  mainAssemblyTime; //  how long does the main station take?
    int  finishingAssemblyTime; //  how long does the main station take?
    bool mainBusy; // is the main station busy?
    bool finishingBusy; // is the finishing station busy?
    int completelyAssembledItems; // number of items made
    int cumulativeBuildTime; // the total amount of time to build all items
    float averageBuildTime; // avg time to build item
public:
    Simulation(); //TODO: build the part Queues when simulation is built

    // TODO: you need methods to manipulate product and part queues.
    // [add them here.]

    // add to the respective queues
    void addPartZero(PartZero *part);
    void addPartOne(PartOne *part);
    void addPartTwo(PartTwo *part);
    void addPartialProduct(PartialProduct * product);

    // dequeue the respective queues
    int popMainParts(); // pops p0 and p1 and returns the earliest of arrivalTimes
    void popPartZero();
    void popPartOne();
    void popPartTwo();
    PartialProduct* popPartialProduct();

    // functions that check if queues have parts in
    bool partsInZero();
    bool partsInOne();
    bool partsInTwo();
    bool partsInProduct();

    int getCompletelyAssembledItems(); // getter
    void completeAssemblyOfItem(); // adds one to completelyAssembledItems var
    void updateCumulativeBuildTime(int time);
    float getAvgBuildTime();

    // main method for driving the simulation
    void runSimulation(char *fileName);

    // add an event to event queue.
    void addEvent (Event*);

    // read next arrival from file and add it to the event queue. 
    bool getNextArrival(); //TODO: add to sim.cpp

    // getter and setter for simulation time
    int getSimulationTime();
    void setSimulationTime(int time);

    // getters for assembly times
    int getMainTime();
    int getFinishingTime();

    // getters and setters for station statuses.
    bool isMainBusy();
    bool isFinishingBusy();
    void setMainStatus(bool);
    void setFinishingStatus(bool);

};// class Simulation

#endif //START_FILES_SIMULATION_H

Simulation. cpp конструктор:

// constructor
Simulation::Simulation() {
    // init part queues
    partQueues = reinterpret_cast<Queue **>(new Queue[3]);
    partQueues[0] = new Queue();
    partQueues[1] = new Queue();
    partQueues[2] = new Queue();

    // init event list
    eventList = new PriorityQueue();

    // init product queue
    productQueue = new Queue();

    // station status
    mainBusy = false;
    finishingBusy = false;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...