简体   繁体   中英

My MakeFile can't find my header directory

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 ?

With your rule

$(NAME): $(OBJS)

the dependency on $(OBJS) will run make s 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) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM