0

I'm trying to install the SDL library for Qt 5.1 on Windows 7, but I'm stuck. I'm a total newbie with using external libraries so please bear with me, I figured this sort of thing would be pretty basic to set up.

I downloaded the SDL-devel-1.2.15-mingw32.tar.gz (Mingw32) file, extracted it, and in my project's PRO file I added:

INCLUDEPATH += "C:\SDL\SDL-1.2.15\include\SDL"

LIBS += "C:\SDL\SDL-1.2.15\bin\SDL.dll"

Now when I try to compile this:

#include <iostream>
#include <stdlib.h>
#include "SDL.h"
using namespace std;

int main()
{
    SDL_Init( SDL_INIT_EVERYTHING );
    cout << "Hello World!" << endl;

    return 0;
}

I get this:

crt0_c.c:-1: error: undefined reference to `WinMain@16'

collect2.exe:-1: error: error: ld returned 1 exit status

Community
  • 1
  • 1
Farlo
  • 17
  • 7

2 Answers2

0

Compiling with SDL and g++ cannot find -lSDLmain etc

Undefined reference to WinMain@16 when using SDL

I am sure one of those is also applicable to your question.

Community
  • 1
  • 1
Greenflow
  • 3,935
  • 2
  • 17
  • 28
  • What's the syntax for adding the linker path and those compiler flags? (I'd ask on those threads but it says I need 50 rep.) – Farlo Aug 10 '13 at 22:55
  • http://stackoverflow.com/questions/5314735/how-to-add-external-libraries-to-qt4-application-c same for Qt5 – Greenflow Aug 10 '13 at 23:01
  • Hey hey, it done worked. Thank you for dealing with my noobishness. – Farlo Aug 11 '13 at 02:05
  • We all were noobs once. And on the majority off topics we still are and will ever be. :-) – Greenflow Aug 11 '13 at 02:10
0

SDL should be prevented from overloading main method. To do so, add the following piece of code wherever you include SDL headers.

#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>

#ifdef __MINGW32__
#undef main /* Prevents SDL from overriding main() */
#endif

To make it working in your case, your project.pro file should be like this:

LIBS += -LC:\SDL-devel-1.2.15-mingw32\SDL-1.2.15\lib -llibSDL
INCLUDEPATH +=C:\SDL-devel-1.2.15-mingw32\SDL-1.2.15\include

As it is eveident from my code, I am using sdl version 1.2.15, 32-bit for mingw compiler on Windows 8.

Reference:

To find a good tutorial about the SDL ffmpeg integration, you can refer to dranger.

Davood Falahati
  • 1,474
  • 16
  • 34