1
votes

I was struggling with using SDL2 and Qt Creator and found some threads here on SO that were mostly helpful but nothing that put it all together for SDL2 and Qt Creator on Windows 10. The main issue was that I could not use the console for I/O at the same time as SDL2 and following the other recommendations, a number of different things went wrong.

There were two keys:

  1. Which SDL2.dll file to use and which directory to place it.
    Some said use the SDL2.dll file download from the SDL website. Others said put this file in the main project directory, which did not work for me. What worked for me was first doing a build of my project (which failed) but creates a "build-..." directory. Then, taking the SDL2.dll file from installDir\SDL2-2.0.5\i686-w64-mingw32\bin and placing it in the "build-..." directory.
  2. In the project.pro file, adding manually:
    INCLUDEPATH += installDir/SDL2-2.0.5/i686-w64-mingw32/include
    LIBS += -L installDir/SDL2-2.0.5/i686-w64-mingw32/lib -lmingw32 -mwindows -mconsole -lSDL2main -lSDL2
    CXXFLAGS = -std=c++11

To be honest, I don't know if all of the calls in LIBS are needed, but it's now working perfectly for me and I thought I'd share some knowledge.

1
How about the result? I'm trying to use SDL_mixer in Qt5 too but when I compile, the out put: undefined reference to `Mix_FuncName': Mix_Init, Mix_Linked_Version. - aviit

1 Answers

0
votes

Where to put the DLL

The dll, is required to be in a directory which match one of the following rules:

  • Is part of the $PATH$ environment variable
  • Is in the same directory than the executable
  • Is in a directory which is actively specified in your code and loaded "manually".

In my case, I just moved those DLL to my /bin folder.

Libs and includes

Includes are required for the compiler, for this purpose, both of the following possibilities match:

  • Copy the SDL includes in the compiler include directory.
  • Add the include path to the project using INCLUDEPATH as explained by @launchpadmcquack.

Libs are required by the linker, for this purpose, both of the following possibilities match:

  • Copy the SDL libs in the compiler lib directory.
  • Add the lib to the project using LIBS as explained in the question.

Considering the library list, SDL2 is required, others depends on you specific projects. E.g. In my case I do not link any of the mingw32, mwindows or mconsole.

Additional note: You may specify C++11 with the CONFIG parameter:

CONFIG *= c++11