C++ Makefile, Redefinition of class [duplicate]

This question already has an answer here:

So I’m trying to make a very simple makefile for my program. The program has 6 classes with inheritance and I have created separate .h and .cpp files for each of them.

The problem I am having is that when I run the makefile I get an error telling me:

In file included from Items.h:2:0,
             from GraphicsCards.h:3,
             from GraphicsCards.cpp:1:
Orders.h:5:7: error: redefinition of ‘class Orders’
Orders.h:5:7: error: previous definition of ‘class Orders’
make: *** [GraphicsCards.o] Error 1

Below is my Makefile:

# all - compile the program if any source files have changed
all: Orders.o Customers.o Items.o GraphicsCards.o Proccessors.o HardDrives.o driver.o
g++ Orders.o Customers.o Items.o GraphicsCards.o Proccessors.o HardDrives.o driver.o -o program

# Orders.o
Orders.o: Orders.cpp Orders.h
g++ -c Orders.cpp -o Orders.o

# Customers.o
Customers.o: Customers.cpp Customers.h
g++ -c Customers.cpp -o Customers.o

# Items.o
Items.o: Items.cpp Items.h
g++ -c Items.cpp -o Items.o

# GraphicsCards.o
GraphicsCards.o: GraphicsCards.cpp GraphicsCards.h
g++ -c GraphicsCards.cpp -o GraphicsCards.o

# Proccessors.o
Proccessors.o: Proccessors.cpp Proccessors.h
g++ -c Proccessors.cpp -o Proccessors.o

# HardDrives.o
HardDrives.o: HardDrives.cpp HardDrives.h
g++ -c HardDrives.cpp -o HardDrives.o

# driver.o
driver.o: driver.cpp Orders.h Customers.h Items.h GraphicsCards.h Proccessors.h HardDrives.h
g++ -c driver.cpp -o driver.o

# clean - delete the compiled version of your program and
# any object files or other temporary files created during compilation.
rm -f *.o program

As an example this is what my GraphicsCards.h file looks like:

#include <string>
#include "Orders.h"
#include "Items.h"

using namespace std;

class GraphicsCards: protected Items
    int speed;
    string model;
    int memory;

Also all of my x.cpp files have #include “x.h” as their first line

I’m fairly new to C++ coding so even if you cant help me with my question any tips or advice would be greatly appreciated!

Source: c++

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.