Search code examples
windowsqtsdlsdl-2

Undefined reference to SDL_Init with Qt Creator


I'm trying to build the following basic SDL2 application with Qt Creator (Qt 5.1.1).

SDLTest.pro :

TARGET = SDLTest01
CONFIG   += console

TEMPLATE = app

INCLUDEPATH += C:\Users\Martin\code\libs\SDL2-2.0.1\x86_64-w64-mingw32\include
LIBS += -LC:\Users\Martin\code\libs\SDL2-2.0.1\x86_64-w64-mingw32\lib -lSDL2

SOURCES += main.cpp

main.cpp :

#include <SDL2/SDL.h>

#include <QCoreApplication>
#undef main
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
        return 1;

    return a.exec();
}

But I have the following error:

undefined reference to `SDL_Init'

The same code with the according reference compile ok with SDL 1.2.

Any idea?


Solution

  • I posted the answer as a comment, but in case someone in future has a similar problem here's the solution.

    The error "undefined reference" means that there is a prototype that defined, but there is no definition to be found. Most commonly you are not linking to the library that has the definition.

    In the authors case he was linking to a library meant for x86_64, but his target application was i686 so the linker couldn't find the reference for his target. Linking to the correct library for his target solved his problem.