•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,597 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,453 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 537 | Replies: 6
![]() |
•
•
Join Date: Feb 2006
Location: Illinois
Posts: 14
Reputation:
Rep Power: 3
Solved Threads: 0
I know this is probably an unbelievably simple error somewhere, but I can't see it. I keep getting "undefined reference to Machine::Machine()" and all of Machine's other functions.
main.cpp
machine.h
machine.cpp
I know I'm going to kick myself once someone answers this. Thanks in advance.
-andrax
main.cpp
#include "machine.h"
using namespace std;
int main(int argc, char** argv) {
Machine* m = new Machine();
m->reset();
m->run();
delete m;
return 0;
}machine.h
#ifndef _MACHINE_H_
#define _MACHINE_H_
#include "user.h"
class Machine {
public:
Machine();
~Machine();
void run();
void reset();
private:
User currentUser;
};
#endifmachine.cpp
#include "machine.h"
Machine::Machine() {
}
Machine::~Machine() {
}
void Machine::run() {
}
void Machine::reset() {
}I know I'm going to kick myself once someone answers this. Thanks in advance.
-andrax
•
•
Join Date: Feb 2006
Location: Illinois
Posts: 14
Reputation:
Rep Power: 3
Solved Threads: 0
Doesn't get to compile at all. The error keeps it from getting that far.
Makefile
Makefile
OBJS = main.o machine.o user.o
EXENAME = sucrose
C = g++
COPTS = -g -Wall
LINK = g++
LINKOPTS = -o $(EXENAME)
$(EXENAME): $(OBJS) $(LINK) $(LINKOPTS) $(OBJS)
main.o : main.cpp machine.h
$(C) $(COPTS) main.cpp
machine.o : machine.cpp machine.h user.h
$(C) $(COPTS) machine.cpp
user.o : user.cpp user.h
$(C) $(COPTS) user.cpp
clean:
-rm *o $(EXENAME) > $(EXENAME): $(OBJS) $(LINK) $(LINKOPTS) $(OBJS)
Shouldn't this be
Also, COPTS should also include the -c command line flag. This means "compile only", and is necessary to turn each file into its corresponding .o file. As written, each target tries to compile and link the whole program, which will cause the problem you see.
Does typing this at the command line also work?
Shouldn't this be
$(EXENAME): $(OBJS)
$(LINK) $(LINKOPTS) $(OBJS)Also, COPTS should also include the -c command line flag. This means "compile only", and is necessary to turn each file into its corresponding .o file. As written, each target tries to compile and link the whole program, which will cause the problem you see.
Does typing this at the command line also work?
g++ main.cpp machine.cpp user.cpp ![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- help (overload << in a template class ) (C++)
- problem instantiating a subclass of abstract class (C)
- function takes 0 arguments error - probably a dumb question (C++)
- Error help (Java)
- i need help with main with class (C)
- '[Class] is not abstract..' error when i use 'implements' (Java)
Other Threads in the C++ Forum
- Previous Thread: Write text to an 'Edit Control' - (C++/MFC)
- Next Thread: Easiest way to read stream of bits as a String



Linear Mode