0

I have had an error fixed with sdl, but another problem was noticed to me by Quentin. (Thanks again for the notice.)

Here is the problem: Nothing from the executable is logged in the console and I had an error where I had to convert a variable to string using .c_str(), but for some reason the compilation did not say anything about it.

Here is what my makefile looks like (I am not really good with makefiles yet as I don't really understand too much how all it works, but this is what I have for now):

#Is it in debug mode?
DEBUG=yes

SHELL='sh -x'

CC = G++

#OBJS specifies which files to compile as part of the project
OBJS = src/main.cpp

#OBJ_NAME specifies the name of the executable
OBJ_NAME = Game

INCLUDE_PATHS = -IC:/mingw_dev_lib/include/SDL2

LIBRARY_PATHS = -LC:/mingw_dev_lib/lib

COMPILER_FLAGS = -w -Wl,-subsystem,windows

LINKER_FLAGS = -lmingw32 -lSDL2main -lSDL2 -lSDL2_image

#This is the target that compiles the executable
all : $(OBJS)
ifeq ($(DEBUG),yes)
        g++ $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) -g $(LINKER_FLAGS) -o Debug\$(OBJ_NAME)
else
        g++ $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o Release\$(OBJ_NAME)
endif
Avarthar
  • 15
  • 1
  • 5
  • was it actually a compiler error that the missing `.c_str()` caused, or was it a runtime error? That is, if you manually ran the appropriate `g++ ...` command, did that give an error? If not, then revise your question to show the code that had the error, and ask us why it caused a runtime error. – lockcmpxchg8b Dec 15 '17 at 05:07
  • Well, apparently a warning was supposed to happen when before parsed a `.c_str()` after the string in my `SDL_Log()` But the problem here is that the compiler was supposed to apparently give a warning for that error. Also, something I'm wondering is that I can't get the executable to log into the console neither when running the `game.exe` from the MingWx64 console. – Avarthar Dec 15 '17 at 07:19
  • Please stop mixing things from compiling and running the program. Either your problem is with compilation, then we talk about compiler errors/warnings and the difference between makefile usage, direct g++ compilation, ... or we talk about problems when executing the program - then you asked the wrong question altogether. – grek40 Dec 15 '17 at 08:19
  • I never asked about the executable thing, it was just something I wrote incase it was related to the same problem when compiling. – Avarthar Dec 15 '17 at 10:29

1 Answers1

1

I guess the problem is kindof obvious once you look at the compiler flags...

Have a look at: Disable all gcc warnings

And then realize, that your COMPILER_FLAGS = -w -Wl,-subsystem,windows contain the -w flag. You should start by removing it (whatever reason it was there in the first place...) and including -Wall (thanks @keltar for pointing this out) instead, then see if the warnings start appearing like you want them.

grek40
  • 13,113
  • 1
  • 24
  • 50
  • I have tried removing `-w` and I understand why it should not have been there in the first place. But I have not managed to get any warning from the compiler. Would you recommend some website to learn more about makefiles I am really new to them and I don't get all of the options in there. – Avarthar Dec 15 '17 at 10:33
  • @Avarthar you haven't requested what warnings compiler should generate; what flags are enabled by default is specific to compiler version. For most common warnings you could add `-Wall` (which, despite the name, doesn't enable all supported warnings). There are other options like `-Wextra` for even more warnings. Refer to gcc manual. – keltar Dec 15 '17 at 10:52
  • @Avarthar if you still need help, you should inspect the generated compiler command (see https://stackoverflow.com/questions/5820303/how-do-i-force-make-gcc-to-show-me-the-commands) and if you can't find the problem, then edit your question to include the generated command. – grek40 Dec 15 '17 at 11:14
  • Alright, thanks a lot for the help. @keltar `-Wall` and `-Wextra` worked perfectly. Now I see every warnings like I wanted originally. – Avarthar Dec 15 '17 at 21:09