1
votes

When I try compiling the file

#include "SDL2\SDL.h"

int main( int argc, char* argv[] )
{
   //Start SDL
   SDL_Init( SDL_INIT_EVERYTHING );

   //Quit SDL
   SDL_Quit();

   return 0;    
}

--an example from the SDL wiki--on the command line with

g++ -o SDL_Test.exe SDL_Test.cpp -lmingw32 -lSDLmain -lSDL

I get an error that says my computer cannot find -lSDLmain and -lSDL. Without the library things, it has trouble interpreting the functions.

I think the problem has something to do with the -l things, but I have no idea what they do....

My computer is 64-bit, if that makes a difference. I copied the x84_64-mingw32 bin, include, and lib into the C:\MinGW versions.

I would mostly just like an explicite solution to my problem, but if you could try explaining the -l things and other - things, that would be awesome.

-::- Answered by greatwolf in chat: turns out I was using 32-bit MinGW with 64-bit SDL files; I just needed to replace the 64-bit files with the 32-bit versions. Also, I had to direct the compiler to my SDL2.dll file. End compile command was g++ -o SDL_Test.exe SDL_Test.cpp -LC:\MinGW\lib -lmingw32 -lSDL2main C:\MinGW\bin\SDL2.dll.

1
where's libsdlmain.a and libsdl.a located? SDL_Init and SDL_Quit needs to be implemented by sdl somewhere and those 2 files tell the linker where that is. - greatwolf
I have two files called libSDL2main.a and libSDL2.a in C:\MinGW\lib. - Jordan
g++ -o SDL_Test.exe SDL_Test.cpp -LC:\MinGW\lib -lmingw32 -lSDL2main -lSDL2 - greatwolf
Many thanks; that got rid of the 'cannot find' errors, but now it's saying 'undefined reference' to SDL_Init/Quit. I tried adding -mwindows on, but no luck. Is it possible that, even though I have a 64-bit computer, I downloaded 32-bit MinGW and that's what's making it not work, or would it not even be getting to this point in that case? - Jordan
Try replacing -lSDL2 with sdl2.dll. Make sure to specify its full absolute path. - greatwolf

1 Answers

0
votes

You've got to make sure that you specify the appropriate search path for libraries using the -L compiler flag. Otherwise it won't know where to look for linking.