makefile is skipping target

I have the following makefile for a project:

VIEW := View
CONTROLLER := Controller
MODEL := Model

all: compilar
compilar: criterio acta persona director jurado asistente universidad view main
    g++ -o Salida Criterio.o Acta.o Persona.o Director.o Jurado.o Asistente.o Universidad.o View.o main.o
criterio: ${MODEL}/Criterio.cpp ${MODEL}/Criterio.h
    g++ -c ${MODEL}/Criterio.cpp
acta: ${MODEL}/Acta.cpp ${MODEL}/Acta.h ${MODEL}/Criterio.h
    g++ -c ${MODEL}/Acta.cpp
persona: ${MODEL}/Persona.cpp ${MODEL}/Persona.h ${MODEL}/Acta.h
    g++ -c ${MODEL}/Persona.cpp
director: ${MODEL}/Director.cpp ${MODEL}/Director.h ${MODEL}/Persona.h
    g++ -c ${MODEL}/Director.cpp
jurado: ${MODEL}/Jurado.cpp ${MODEL}/Jurado.h ${MODEL}/Persona.h
    g++ -c ${MODEL}/Jurado.cpp
asistente: ${MODEL}/Asistente.cpp ${MODEL}/Asistente.h ${MODEL}/Persona.h
    g++ -c ${MODEL}/Asistente.cpp
universidad: ${MODEL}/Universidad.cpp ${MODEL}/Universidad.h ${MODEL}/Asistente.h ${MODEL}/Jurado.h ${MODEL}/Director.h ${MODEL}/Acta.h
    g++ -c ${MODEL}/Universidad.cpp
view: ${VIEW}/View.cpp ${VIEW}/View.h ${MODEL}/Universidad.h
    g++ -c ${VIEW}/View.cpp
main: main.cpp ${VIEW}/View.h 
    g++ -c main.cpp
clean: #comando para borrar los .o y el .exe
    @echo "Cleaning compilation..."
    del *.o, del *.exe

But when I execute make on the console it skips the target view

g++ -c Model/Criterio.cpp
g++ -c Model/Acta.cpp
g++ -c Model/Persona.cpp
g++ -c Model/Director.cpp
g++ -c Model/Jurado.cpp
g++ -c Model/Asistente.cpp
g++ -c Model/Universidad.cpp
g++ -c main.cpp
g++ -o Salida Criterio.o Acta.o Persona.o Director.o Jurado.o Asistente.o Universidad.o View.o main.o
g++: error: View.o: No such file or directory

As you can see, it skips the target “view” so it does not generate View.o

However if I change the name of the target “view” to something like “doview” it works perfectly. I tried looking up for reserved words on makefiles but I could not find anything related to this. Why does this happen? I’m new to makefiles.

Answer

view: ${VIEW}/View.cpp ${VIEW}/View.h ${MODEL}/Universidad.h
    g++ -c ${VIEW}/View.cpp

declares that you are going to create a file called view and that the inputs are ${VIEW}/View.cpp ${VIEW}/View.h ${MODEL}/Universidad.h. As your command actually produces a file called View.o your makefile won’t work. You need:

View.o: ${VIEW}/View.cpp ${VIEW}/View.h ${MODEL}/Universidad.h
    g++ -c ${VIEW}/View.cpp

(your other targets have the same issue).

You also need to mark all your targets that don’t produce a file as phony:

.PHONY: clean all

As compilar isn’t a phony target and produces a single file it should be renamed to Salida