简体   繁体   English

g ++:没有这样的文件或目录?

[英]g++: No such file or directory?

(On Linux, trying to set up SDL) I'm having a time with makefiles, I'm finding them hard to learn. (在Linux上,尝试设置SDL)我花了一些时间来处理makefile,发现它们很难学习。 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. 这是我的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)

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)$(SDL_CFLAGS)来制作$(TARGET)或更好地从CFLAGS删除-o并将其直接放在$@之前:

...
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. -o选项应紧邻要生成的可执行文件的名称。 In your original Makefile it is part of $(CFLAGS) and is followed by the C flags of the SDL library. 在您的原始Makefile它是$(CFLAGS)一部分,后跟SDL库的C标志。 Therefore the compiler tries to link in game.exe (the $@ ) instead of producing an executable file by that name. 因此,编译器尝试链接game.exe$@ )而不是使用该名称生成可执行文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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