install SDL on QT

-2

i trying it nearly 5 hours and still cannot setup to run helloWorld SDL on QT. please help me. 1) first of all i download from site developer package SDL2-devel-2.0.1-mingw.tar.gz (MinGW 32/64-bit) and there i686 and simple x86, which of them i need to add ? i download this package

2) then i add all bin, lib, include in C:\Qt\Qt5.0.2\5.0.2\mingw47_32

my Pro file:

INCLUDEPATH += $$PWD/../../../../5.0.2/mingw47_32/include

## Glut / OpenGL
unix|win32: LIBS += -L$$PWD/../../../../5.0.2/mingw47_32/lib/ -lglut32
unix|win32: LIBS += -lOPENGL32

When i start app, get error.

C:\Qt\Qt5.0.2\Tools\QtCreator\bin\check_sdl\main.cpp:10: ошибка: undefined reference to `SDL_Init'

When in Pro file add rows

INCLUDEPATH += "C:\\SDL2-2.0.1\\i686-w64-mingw32\\include"
LIBS += -L"C:\\SDL2-2.0.1\\i686-w64-mingw32\\lib\\" \
-lmingw32\
-libSDL2main.a\
-lSDL2_test.a\

then error is

:-1: ошибка: cannot find -libSDL2main.a

however this file are there . enter image description here

so i have no idea what to do :/

UPDATE:

INCLUDEPATH += "C:\\SDL2-2.0.1\\x86_64-w64-mingw32\\include\\SDL2"
LIBS += -L"C:\\SDL2-2.0.1\\x86_64-w64-mingw32\\bin\\SDL2"

again undefined SDL Q_Q

UPDATE 2:

INCLUDEPATH += C:\SDL2-2.0.1\i686-w64-mingw32\include
LIBS += -L"C:\SDL2-2.0.1\i686-w64-mingw32\lib" \
-lmingw32\
-lSDL2main\
-lSDL2\


#include "SDL2/SDL.h"
using namespace std;

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

    SDL_Quit();

    return 0;
}

\Users\slouken\release\SDL\SDL2-2.0.1-source\src\main\windows\SDL_windows_main.c:140: ошибка: undefined reference to `SDL_main'

UPDATE 3 Now it's running, but crashing on start)

#include "SDL2/SDL.h"
#include "SDL2/SDL_main.h"
//#include "SDL.h"


#undef main

using namespace std;

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

    cout << "hell";
    int i = 4 +4 ;
    cout << "i is: " << i;

    //Quit SDL
   // SDL_Quit();

   return 0;
}

Crash with error 0x00000135

c++
qt
sdl
asked on Stack Overflow Dec 25, 2013 by gronzzz • edited Dec 25, 2013 by gronzzz

2 Answers

1

Both SDL and Qt provide OpenGL drawing surfaces - why do you need SDL when you already use Qt?

anyway, that

undefined reference to `SDL_Init'

is a linker error, and it happens because you have -libSDL2main.a instead of -lSDL2main in your flags, so the file and it's symbols are not found.

first update:

undefined reference to `SDL_main'

this might be a signature mismatch.

You should declare the main function with the usual int main(int, char**) signature, because the arguments are important for SDL, as it tries to capture them.

Check this answer: SDL Error Undefined symbols for architecture x86_64 "_SDL_main"

second update:

0x00000135 means DLL not found (at runtime).

You can use this tool (http://dependencywalker.com) to check if all the libraries are being found - maybe some unsatisfied mingw support library dependency is killing your program.

answered on Stack Overflow Dec 25, 2013 by sid_cypher • edited May 23, 2017 by Community
0

Ok let's give answers what's was my troubles.

  1. I was using wrong x86_64-w64-mingw32. I needed to use i686-w64-mingw32
  2. Forgot to add SDL2.dll into C:/Windows or into folder with *.exe
  3. right main is " int main(int argc, char* argv[]) "
  4. Right paths are :

    INCLUDEPATH += C:\SDL2-2.0.1\i686-w64-mingw32\include
    LIBS += -L"C:\SDL2-2.0.1\i686-w64-mingw32\lib" \
    -lmingw32\
    -lSDL2main\
    -lSDL2\
    
  5. also dependency walker told me to add libwinpthread-1.dll, i also add this into folder.

Thanks all for help!

answered on Stack Overflow Dec 25, 2013 by gronzzz

User contributions licensed under CC BY-SA 3.0