![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 3
| Linux G++ Makefile (Or C++ Code) 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 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
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
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
|
| NOX is offline | |
| | #2 |
| a_capitalist_story Join Date: Dec 2007
Posts: 993
| So...how does the Makefile know how to make Road.o? Or any of the other .o files? |
| rags_to_riches is offline | |
| | #3 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 3,029
| Your makefile should probably look more like this: Code: CXXFLAGS=-O3
all: main
main: Road.o
Queue.o: Queue.cpp Vehicle.o
Road.o: Road.cpp
Vehicle.o: Vehicle.cpp
clean:
rm *.o main
__________________ bit∙hub [bit-huhb] n. A source and destination for information. |
| bithub is offline | |
| | #4 |
| Registered User Join Date: Apr 2006
Posts: 1,337
| I disagree with bithub. You want the object files to depend on both their associated source files, and their included non library headers. You don't want the object files to depend on each other. Main should depend on all of the object files.
__________________ It is too clear and so it is hard to see. A dunce once searched for fire with a lighted lantern. Had he known what fire was, He could have cooked his rice much sooner. |
| King Mir is offline | |
| | #5 | |||
| Registered User Join Date: Oct 2009
Posts: 3
| Quote:
Quote:
Quote:
So pretty much what I am asking is, if Road depends on Queue, then why wouldn't I make it so in the Makefile? | |||
| NOX is offline | |
| | #6 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 10,163
| It is highly unlikely that Road depends on Queue.o. (I'm assuming here that Road does not contain your main function.) It may well depend on Queue.h. It can call functions that live in Queue.o, which is not at all the same thing as depending on Queue.o. |
| tabstop is offline | |
| | #7 | |
| Registered User Join Date: Apr 2006
Posts: 1,337
| Quote:
Road.o does need to depend on Queue.h, because it includes that header.
__________________ It is too clear and so it is hard to see. A dunce once searched for fire with a lighted lantern. Had he known what fire was, He could have cooked his rice much sooner. | |
| King Mir is offline | |
| | #8 |
| Registered User Join Date: Oct 2009
Posts: 3
| Ok, I understand now, thank you very much ^_^ -NOX |
| NOX is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dabbling with Linux. | Hunter2 | Tech Board | 21 | 04-21-2005 04:17 PM |
| Binary Search Trees Part III | Prelude | A Brief History of Cprogramming.com | 16 | 10-02-2004 03:00 PM |
| Compile my code for Linux? | CompiledMonkey | Linux Programming | 5 | 11-17-2002 02:02 AM |
| << !! Posting Code? Read this First !! >> | kermi3 | Linux Programming | 0 | 10-14-2002 01:30 PM |
| Can you have nested code block? What does the compiler do? For example ... | albertr | C Programming | 4 | 01-16-2002 12:04 AM |