Sign in to follow this  

SDL with Dev-C++

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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++)

Share this post


Link to post
Share on other sites
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:

[code]
#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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this