g++: No such file or directory?

放肆的年华 提交于 2019-12-12 04:03:20

问题


(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:


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.



来源:https://stackoverflow.com/questions/10895879/g-no-such-file-or-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!