If you put only this in a Makefile and call make:
%.o: %.cpp
g++ -g -o $@ -c $<
It tells: make: *** No targets. Stop.
Because it's not a target. It's a rule.
It will work if your another target needs a .o file.
main.exe: main.o add.o
g++ -g -o $@ $^
%.o: %.cpp
g++ -g -o $@ -c $<