On my Linux VM I have everything installed correctly and updated properly. I really am new to Makefiles, so before you point me to a tutorial I just need to understand why my code is not compiling.
Actually, I can make it compile, but what I have to do does not seem right at all. What I do to "fix" this error is make "Queue.o" a dependency in main, but it shouldn't depend on the Queue class...For now it should just depend on the road class...
Error:
Code:
Road.o: In function 'Road::Road(int, int)':
Road.C: (.text+0x56): undefined reference to 'Queue::Queue(char)'
Road.o: In function 'Road::Road(int, int)':
Road.C: (.text+0x86): undefined reference to 'Queue::Queue(char)'
collect2: ld returned 1 exit status
make *** [main] Error 1
Makefile:
Code:
CXXFLAGS=-O3
all: main
main: Road.o
Queue.o: Queue.h Vehicle.o
Road.o: Road.h
Vehicle.o: Vehicle.h
clean:
rm *.o main
Queue Class Header:
Code:
#ifndef _QUEUE_H_
#define _QUEUE_H_
#include "Vehicle.h"
#include <cstdlib>
struct QNode;
class Queue{
public:
/* CONSTRUCTORS */
Queue();
/* OBSERVERS */
bool IsEmpty() const{return pHead==NULL;};
int Size() const{return size;};
void Print() const;
/* TRANSFORMERS */
void Dequeue();
void Enqueue(Vehicle * pV);
private:
QNode * pHead;
QNode * pTail;
int size;
};
#endif
Road Class Header:
Code:
#ifndef _ROAD_H_
#define _ROAD_H_
#include "Queue.h"
class Road{
public:
/* CONSTRUCTORS */
Road(int id, int travelTime = (rand() % 20) + 1);
/* OBSERVERS */
int GetID() const{return _id;};
int GetTravelTime() const{return _travelTime;};
void Print() const;
/* TRANSFORMERS */
void AddVehicle();
void RemoveVehicle();
void SetID(int newID);
void SetTravelTime(int newTime);
private:
Queue _road;
int _id;
int _travelTime;
};
#endif