0

Whenever I try and compile with mingw32-make -f .\MakeFile it outputs this error:

g++ -Iinclude -Iinclude/sdl -Iinclude/headers -Llib -o test src/*.cpp -lmingw32 -lSDL2main -lSDL2 -lSDL2_image

C:\Users\spr\AppData\Local\Temp\ccpQRKDb.o:main.cpp:(.text+0xf): undefined reference to `SDL_Init'
C:\Users\spr\AppData\Local\Temp\ccpQRKDb.o:main.cpp:(.text+0x33): undefined reference to `SDL_GetError'
C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x39): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [.\MakeFile:2: all] Error 1

Here is the code:

#include <SDL.h>
#include <SDL_image.h>
#include <iostream>

int main(int argc, char* argv[])
{
    if(SDL_Init(SDL_INIT_VIDEO) > 0)
    {
        std::cout << "SDL_INIT FAILED. SDL_ERROR: " << SDL_GetError() << std::endl;
        return 1;
    }

    return 0;
}

I followed this tutorial on how to set up SLD2 with VScode on Windows: https://www.youtube.com/watch?v=9Ca-RVPwnBE

spr shb
  • 81
  • 6
  • `WinMain` indicates that you are compiling this for Windows. – Neil Jan 30 '22 at 01:08
  • Yeah, I am compiling on windows. – spr shb Jan 30 '22 at 01:11
  • 2
    The order of the `-l` arguments may be significant. Maybe try different orders. – user17732522 Jan 30 '22 at 01:12
  • I mean, this is a console programme, by `main()`, but the compiler, in it's current configuration, expects a Windows GUI programme using `WinMain()`. (I don't know how, because `-mwindows` doesn't seem to be in there; maybe SDL sets it?) – Neil Jan 30 '22 at 01:23
  • `WinMain` is implemented in `SDL2_main`, that's not a problem. Looks like your libraries are for different architecture than the one you're building for, and linker silently skips incompatible libraries. Looks like your compiler prefix is `i686-w64`; make sure contents of your `lib` directory (or other preset directories, if you placed your libs there) contains `i686` libraries. – keltar Jan 30 '22 at 07:40
  • 1
    @keltar yea that seemed to be the problem I got it fixed, thank you! – spr shb Jan 30 '22 at 15:44

0 Answers0