catch2c++;链接器问题--包含类的未定义符号 一个C++学校项目的工作。似乎无法使catch2测试正常工作
我有一个编译项目的makefilecatch2c++;链接器问题--包含类的未定义符号 一个C++学校项目的工作。似乎无法使catch2测试正常工作,c++,catch2,C++,Catch2,我有一个编译项目的makefile 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 StartFinishingAss
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)
以下是测试文件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);
}
#define CATCH_CONFIG_MAIN//这告诉CATCH提供一个MAIN()-只做
这是一个cpp文件
#包括“catch.hpp”
#包括“Simulation.h”
#包括“PartArrival.h”
#包括“PriorityQueue.h”
#包括
使用名称空间std;
无符号整数阶乘(无符号整数){
返回编号,其中定义了Simulation
constructor?你编译它吗?我不是在makefile中编译它吗?我不知道。因此我的问题是:它定义在哪里?clang++--std=c++11-o A2test Test\u PriorityQueue.cpp
这是我为A2test运行的唯一一行,我想我需要指向为我正在运行的类构建的对象文件要在A2Test中使用吗?在哪里定义了Simulation
构造函数?你编译它吗?我不是在makefile中编译它吗?我不知道。因此我的问题是:它定义在哪里?clang++--std=c++11-o A2Test\u PriorityQueue.cpp
这是我为A2Test运行的唯一一行,我想我需要指向为我将在测试中使用的类??
#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);
}
#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
// 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;
}