0

I'm going through LazyFoo's Hello SDL tutorial, and any links to -lSDL2 and -lSDL2main fail to compile due to being "incompatible."

I have my environment variables set up to MinGW32\bin, SDL2-2.0.12\i686-w64-mingw32\include\SDL2 and SDL2-2.0.12\i686-w62-mingw32\bin, and I'm using the tutorial source code to compile. I had to write my own makefile, which is here:

OBJS = SDL2-window-tut.cpp

CC = g++

INCLUDE_PATHS = -IC:\mingw_dev_lib\SDL2-2.0.12\i686-w64-mingw32\include\SDL2

LIBRARY_PATHS = -LC:\mingw_dev_lib\SDL2-2.0.12\i686-w64-mingw32\lib

COMPILER_FLAGS = -std=c++11

LINKER_FLAGS = -lmingw32 -lSDL2main -lSDL2

OBJ_NAME = SDL2-window-tutorial.exe

all: $(OBJS)
    $(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)

When I try to compile I get the following kinds of error for every instance of SDL in the program:

C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:\mingw_dev_lib\SDL2-2.0.12\i686-w64-mingw32\lib/libSDL2main.a when searching for -lSDL2main

C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lSDL2main

My g++ target is x86_64-w64-mingw32, which I know is the source of the problem, but I've run out of ways to fix it. Reinstalling MinGW32 didn't do anything, and I haven't found new information online. Anyone know what's up?

  • 1
    SDL ships two sets of files, 32-bit and 64-bit. You're using the wrong ones (32-bit files with 64-bit compiler). The right files (64-bit) are in the `x86_64-w64-mingw32` directory, rather than `i686-w64-mingw32`. – HolyBlackCat Nov 23 '20 at 06:35
  • Related: [How do I use SDL2 in my programs correctly?](https://stackoverflow.com/questions/64396979/how-do-i-use-sdl2-in-my-programs-correctly) – HolyBlackCat Nov 23 '20 at 06:36
  • Thank you very much! Changing the paths to the 64-bit didn't do anything, but following the link you posted the -m32 flag did the trick. Much appreciated. :) – WatcherMagic Nov 23 '20 at 15:00

0 Answers0