mardi 2 mai 2017

Makefile warning linker input file unused because linking not done

I'm trying to write my own makefile for a C++ program. I'm editing an old makefile for a C program one of my teacher gave m, but I really don't understand why it keeps telling me that linking is not done.

I have 4 classes with their corresponding headers plus the main file.

This is my makefile:

OBJS = main.o Class1.o Class2.o Class3.o Class4.o
HEADERS = Class1.hpp Class2.hpp Class3.hpp Class4.hpp
EXE = main
all: $(EXE)

CXX = g++
CXXFLAGS = -std=c++11 -g -c -Wall
LFLAGS = -Wall -std=c++11 -g

# ---------------------------------------------------------------------
# Rules
# ---------------------------------------------------------------------

RM = rm -rf

.SUFFIXES:
.SUFFIXES: .o .cpp
.cpp.o :
    $(CXX) $(CXXFLAGS) -c -o $@ $<

$(EXE): $(OBJS)
    $(CXX) $(CXXFLAGS) -o $(EXE) $(OBJS)

$(OBJS) : $(HEADERS)

clean:
    $(RM) $(OBJS)
    $(RM) $(EXE)

again:                                                               
    make clean
    make

And these are the error messages I get when I try to compile:

g++: warning: main.o: linker input file unused because linking not done
g++: warning: Class1.o: linker input file unused because linking not done
g++: warning: Class2.o: linker input file unused because linking not done
g++: warning: Class3.o: linker input file unused because linking not done
g++: warning: Class4.o: linker input file unused because linking not done

I understand that this might be because I'm not linking all the .o files together at the end, but isn't it what this line

$(EXE): $(OBJS)
    $(CXX) $(CXXFLAGS) -o $(EXE) $(OBJS)

is supposed to do? Since the -c option is not present.

What am I missing?

Thank you everybody for the help.

Aucun commentaire:

Enregistrer un commentaire