g++: No such file or directory?

2019-09-01 06:21发布

(On Linux, trying to set up SDL) I'm having a time with makefiles, I'm finding them hard to learn. Here is the error I'm getting.

g++: error: game.exe: No such file or directory
make: *** [game.exe] Error 1

Here is my makefile. (Any suggestions on making it better would be great. I've just kind of slapped together whatever I could find to work.)

#Game Make file
TARGET = game.exe
OBJS = App.o\
   App_OnInit.o\
   App_OnEvent.o\
   App_OnLoop.o\
   App_OnRender.o \
   App_OnCleanup.o\

SDL_CFLAGS := $(shell sdl-config --cflags)
SDL_LDFLAGS := $(shell sdl-config --libs)
CFLAGS = -Wall -o
LIBS =
LDFLAGS = 

$(TARGET): $(OBJS)
       g++ $(CFLAGS) $(SDL_CFLAGS) $@  $(LDFLAGS) $(OBJS) $(SDL_LDFLAGS) $(LIBS)
%.o: src/%.cpp
       g++  -c $(SDL_CFLAGS) $< $(SDL_LDFLAGS)

.PHONY: clean
clean:
    rm -f $(TARGET) $(OBJS)

1条回答
Anthone
2楼-- · 2019-09-01 06:53

You could either exchange $(CFLAGS) and $(SDL_CFLAGS) in the rule to make $(TARGET) or better remove -o from CFLAGS and put it directly before $@:

...
CFLAGS = -Wall
...
$(TARGET): $(OBJS)
       g++ $(CFLAGS) $(SDL_CFLAGS) -o $@  $(LDFLAGS) $(OBJS) $(SDL_LDFLAGS) $(LIBS)

-o option should immediately precede the name of the executable file to be produced. In your original Makefile it is part of $(CFLAGS) and is followed by the C flags of the SDL library. Therefore the compiler tries to link in game.exe (the $@) instead of producing an executable file by that name.

查看更多
登录 后发表回答