Skip to content
Advertisement

Error while trying to compile an c++ sdl2 program with mingw

Basically, when I’m trying to compile my program for windows on linux, I get such an error:

/usr/lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld: ../libs/SDL2-2.24.0/x86_64-w64-mingw32/lib//libSDL2main.a(SDL_windows_main.o): in function `main_getcmdline':  
/Users/valve/release/SDL/SDL2-2.24.0-source/foo-x64/../src/main/windows/SDL_windows_main.c:82: undefined reference to `SDL_main'
collect2: error: ld returned 1 exit status

My main function starts like this:

int main(int argv, char* args[])

My compiling script looks like this:

#!/bin/bash
x86_64-w64-mingw32-c++ -I../libs/SDL2-2.24.0/x86_64-w64-mingw32/include/ -L../libs/SDL2-2.24.0/x86_64-w64-mingw32/lib/ -I../libs/SDL2_image-2.6.2/x86_64-w64-mingw32/include/ -L../libs/SDL2_image-2.6.2/x86_64-w64-mingw32/lib/ -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -mwindows

And this is my file structure:

☃️
├── my-project <where I run my script>
│   └── main.cpp
├── my-script.sh
└── libs
    ├── SDL2-2.24.0
    └── SDL2_image-2.6.2

Any clues on why can’t I compile it?

Advertisement

Answer

Oh, okay I was just dumb, didn’t pass the name of main.cpp to the compiler.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement