user2460978
user2460978

Reputation: 725

makefile does not use the compiler flags

I have this makefile:

CC=g++
DEPS = object.hpp utils.hpp
OBJ = object.o main.o

%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< -Wall -lglut -lGL

main: $(OBJ)
    $(CC) -o $@ $^ -Wall -lglut -lGL

Then, when I make make, this happens:

$ make
g++    -c -o object.o object.cpp

When I wanted:

$ make
g++    -c -o object.o object.cpp -Wall -lglut -lGL

How can I achieve this behaviour?

Upvotes: 0

Views: 55

Answers (1)

MadScientist
MadScientist

Reputation: 101081

Well, your rule specifies how to build a .o from a .c. But your files are named .cpp, not .c. Rewrite:

%.o: %.cpp $(DEPS)
        $(CC) -c -o $@ $< -Wall -lglut -lGL

However, adding linker flags like -l to your compile lines will lead to errors.

Upvotes: 1

Related Questions