0

This is my Makefile :

NAME    = pong

SRCS    = src/main.cpp

OBJS    = $(SRCS:.cpp=.o)

CFLAGS  += -lsfml-graphics -lsfml-window -lsfml-system -I include/

all: $(NAME)

$(NAME): $(OBJS)
    g++ -o $(NAME) $(SRCS) $(CFLAGS)

clean:
    rm -f $(OBJS)

fclean: clean
    rm -f $(NAME)

re: fclean all

.PHONY: all clean fclean re

When I do make, it tells me that the header I include in my main.ccp does not exist.

#include "prototypes.hpp"

This is my project organisation :

.
├── a.out
├── include
│   └── prototypes.hpp
├── Makefile
├── src
│   └── main.cpp
└── test

And the weirdest thing is that this work when I do

g++ -o test src/main.cpp  -lsfml-graphics -lsfml-window -lsfml-system  -I include/

Any idea why ?

2
  • Does make tell you actually or is it g++? – πάντα ῥεῖ Nov 19 '15 at 21:15
  • 1
    It's g++. g++ -c -o src/main.o src/main.cpp src/main.cpp:2:26: fatal error: prototypes.hpp: Aucun fichier ou dossier de ce type #include "prototypes.hpp" ^ compilation terminated. – Dimitri Danilov Nov 19 '15 at 21:20
1

With your rule

$(NAME): $(OBJS)

the dependency on $(OBJS) will run makes implicit ℅.o : ℅.cpp rule first, which in turn uses $CXXFLAGS and thus doesn't see the -I option.

As your rule is written, just omit the dependency on $(OBJS).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.