SDL with Dev-C++

Started by
7 comments, last by Bouga 19 years, 8 months ago
Hi, i'm having problems getting SDL to work with the Dev-C++ compiler. As soon as i include the sdl.h the compiler gives me a "[Linker error] undefined reference to `WinMain@16'" error. What i do is: 1) File->New->Project->Empty project 2) File->New->Source File->Add it to project I use this code:

#include <stdio.h>
#include <conio.h>

int main()
{
    printf("Blah");
    getch();
}
And everything works fine. But when i change it to this:

#include <stdio.h>
#include <conio.h>
#include <sdl\sdl.h>

int main()
{
    printf("Blah");
    getch();
}
It gives me a "[Linker error] undefined reference to `WinMain@16'" error. I have downloaded the includes and lib's from here: http://www.libsdl.org/download-1.2.php (the SDL-devel-1.2.7-mingw32.tar.gz (Mingw32) under Win32). Of course i could go with writing a windows application(by using WinMain(...) as the main function) that just uses SDL but what about the portability? Such a program wont be able to run on Linux &stuff, right?. As i understand with SDL you should be able to write an application that runs on any SDL supported OS. So my question is - what am i doing wrong and how should i go about writing an app that runs on many OS and uses SDL?
"A screen buffer is worth a thousand char's" - me
Advertisement
SDL requires main to be defined with a footprint of int main(int, char**), simply change your main definition to that if you don't need command line arguments, but you can't use main() with SDL because it needs the command line arguments (specifically the path).

are you linking with libSDL.a and libSDLmain.a (add -lSDL and -lSDLmain in your linker settings, order may matter, so if it doesn't work play around with it)
Well, i tried:

#include <sdl\sdl.h>#include <stdio.h>#include <conio.h>int main(int argc, char** argv){    printf("Blah");    getch();    return 0;}


And "-lSDLmain -lSDL" in the linker setting (have tried switching the orded) but it's still the same!
"A screen buffer is worth a thousand char's" - me
Did you create a console or windows app? Perhaps try switching. I'm on my desktop at the moment but my laptop has Dev-C++ on it, I'll give it a try soon. (it's been a while since I've used Dev-C++)
-lmingw32 -lSDLmain -lSDL
Dolphins - The sharks of the sea.
And happybara saves the day! :) But thanks anyway, cozman, Ratings for you both :)
"A screen buffer is worth a thousand char's" - me
So the SDL seems to working right, all the examples i tried compiled and run succesfully, but there is one thing that bugs me. The printf() and cout << functions dont work. Heres one example from the SDL documentation:


#include <sdl\SDL.h> //changed this line from "SDL.h" since i keep the includes in a different place
#include <stdio.h>

int main(int argc, char *argv[]) {

printf("Initializing SDL.\n");

/* Initialize defaults, Video and Audio */
if((SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)==-1)) {
printf("Could not initialize SDL: %s.\n", SDL_GetError());
return -1;//changed from exit(-1)
}

printf("SDL initialized.\n");

printf("Quiting SDL.\n");

/* Shutdown all subsystems */
SDL_Quit();

printf("Quiting....\n");

return 0;//changed from exit(0)
}
[\code]

It runs OK, but the printf() functions have no effect. Any idea how to fix that?
"A screen buffer is worth a thousand char's" - me
look for stdout.txt in yours application directory. it stores consoles output.

if you want to use cout<< you have to add these lines:

#include <iostream>
using namespace std;


//edit:typos
Dolphins - The sharks of the sea.
Ohh, thanks.
"A screen buffer is worth a thousand char's" - me

This topic is closed to new replies.

Advertisement