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.


#include "machine.h"

using namespace std;

int main(int argc, char** argv) {
   Machine* m = new Machine();
   delete m;
   return 0;


#ifndef _MACHINE_H_
#define _MACHINE_H_

#include "user.h"

class Machine {

   void run();
   void reset();

   User currentUser;



#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.

Is machine.cpp in your project / makefile?
Do you ever see machine.cpp being compiled when main.cpp is compiled?

Doesn't get to compile at all. The error keeps it from getting that far.


OBJS = main.o machine.o user.o
EXENAME = sucrose
C = g++
COPTS = -g -Wall
LINK = g++


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

        -rm *o $(EXENAME)

Shouldn't this be

        $(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

I made those changes and it still doesn't work. The command-line statement gave the same error too.

Thanks for waiting a whole month to post "it doesn't work" :icon_rolleyes:

Now try again and post some actual command lines, actual error messages, and the code if it's different from what you originally posted.