1

I've created a game with SDL2 library in ubuntu with the atom editor, and for compiling created a makefile with this code:

game: main.c LoadGame.c Events.c CreateTex.c CollisionDetection.c Render.c gameStatus.c
    gcc main.c LoadGame.c Events.c CreateTex.c CollisionDetection.c Render.c gameStatus.c -w -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -o game -lm -I.

And now I want to create an .exe so I created this makefile:

game: main.c LoadGame.c Events.c CreateTex.c CollisionDetection.c Render.c gameStatus.c
    i686-w64-mingw32-gcc main.c LoadGame.c Events.c CreateTex.c CollisionDetection.c Render.c gameStatus.c -w -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -o game.exe -lm -I.

but it gives this error:

    In file included from /usr/i686-w64-mingw32/include/SDL2/SDL.h:32:0,
                     from main.c:2:
    main.c:8:5: error: conflicting types for ‘SDL_main’
     int main(int argc, char const *argv[]){
         ^
    /usr/i686-w64-mingw32/include/SDL2/SDL_main.h:117:39: note: previous declaration of ‘SDL_main’ was here
     tern C_LINKAGE SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[]);
                                         ^~~~~~~~
    makefile:5: recipe for target 'game' failed
    make: *** [game] Error 1


So I'd like some help so I can create a single .exe file from my sourcecode to run it in windows,while

5
  • 3
    char** and char const ** are different types. Write your main exactly as int main(int argc, char *argv[]) (or char **argv as these types are equivalent here). It is answered in SDL windows FAQ Commented Jul 24, 2019 at 14:25
  • Okay Thank you so much!,new errors, linker errors arrived, but I'll search those up and create a new thread if necessary Thank you!(Btw I'm new in stack overflow how do I close a thread?) Commented Jul 24, 2019 at 15:57
  • 1
    As there is no answer here you write one and accept it. I'd argue lazyfoo tutorials are not good for C as it silently makes some C++ assumptions. Commented Jul 24, 2019 at 16:25
  • 2
    On MinGW you need -lmingw32 -lSDL2main -lSDL2 rather than just -lSDL2. Commented Jul 24, 2019 at 20:31
  • Thank you HolyBlackCat! had a bit time off and was great to have my problem resolved when I got back. Commented Jul 24, 2019 at 21:11

1 Answer 1

2

Okay so, as keltar mencioned it looks like the problem was that in my program,

int main(int argc, char const *argv[]) 
the argv array was constant which as stated in here it won't work. So the correct code would be:

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.