I have been trying to use g++ to compile a program with SDL.
The program is only a main.cpp file with two SDL test lines in it, like this:
#include "SDL/SDL.h"
using namespace std;
int main(void) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Quit();
return 0;
}
But my problem is that I get an error to do with the SDL libraries.
First of all I installed MinGW32 so that I could learn about C++11, so when I ask what version GCC is it says that it is version 4.7.0
.
Then I downloaded the SDL-devel-1.2.15-mingw32.tar.gz
file from the SDL website and extracted the folder to the desktop.
After that I copied all of the header files from /SDL-1.2.15/include/SDL
to C:/MinGW/include/SDL
Then I copied 3 files from the /SDL-1.2.15/lib
folder to the C:/MinGW/lib folder
They were:
libSDL.dll.a
libSDL.la
libSDLmain.a
And finally I copied the SDL.dll
file from the bin directory to the same directory that the .exe file will be compiled from.
I think I have set everything up correctly, but I get two different messages based on how I try to compile it.
First of all I tried compiling it using the build system functionality in the Sublime Text 2 editor.
This is the command that I have told Sublime Text 2 to run:
"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}", "-lmingw32 -lSDLmain -lSDL -mwindows"]
When I run this I get the error message:
c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/bin/ld.exe: cannot find lmingw32 -lSDLmain -lSDL -mwindows
collect2.exe: error: ld returned 1 exit status
[Finished in 0.3s with exit code 1]
So I then tried to compile directly from the command prompt.
I changed the directory to the same directory as my main.cpp and ran the following:
g++ main.cpp -o main.exe -lmingw32 -lSDLmain -lSDL -mwindows
And got the following error message:
c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../libSDLmain.a(SDL_win32_main.o): In function `console_main':
/Users/slouken/release/SDL/SDL-1.2.15/./src/main/win32/SDL_win32_main.c:315: undefined reference to `_SDL_main'
collect2.exe: error: ld returned 1 exit status
Can anybody see what I am doing wrong?
Why is it that I get two different messages depending on where I run the command from, and how can I fix this?
Any help would be appreciated.