# Can't Get SDL Started!

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

## Recommended Posts

Hi, I'm trying to learn how to program in SDL, but can't seem to get it started. I'm using Dev-C++ and every time I include "SDL/SDL.h" I get an error in my program. I've done something wrong, but I don't know what. I am using the Lazy Foo Tutorials and I'm pretty sure I did everything right. I'd like to stick to these tutorials if I can, they're quite good. Thanks in return. :)

##### Share on other sites
What error are you getting? may help narrow it down. You will need to tell the linker where to find the SDL library files (.DLL/.lib etc).

I recently began SDL programming with Visual C++ and Win Xp.

##### Share on other sites
The IDE says there is no such file or directory. How do I tell the linker were to find the files?

##### Share on other sites
When you include the header for SDL you also need to tell the linker where to find the library. The SDL header info is contained in the libraries, your compiler has not found these libraries either because they arnt in any of the default search paths/directories or you havent specified explicitly where it should look.

I havent used your IDE though, so cant tell you how to do that, check the IDE help docs with regards to adding DLL's/.libs etc.

##### Share on other sites
I've looked into it, and I have linked the files. (Unkowningly!)

##### Share on other sites
hello,

I've downloaded SDL1.2 to use it with Dev-C++, but when i unpacked it, there were no folders in it, just a bunch of files. So now I don't know which file to copy where. I've found four libSDL files, and none called bin or include.

can anyone help me out?

##### Share on other sites
This is wrong. There should be folders. You might have downloaded the wrong thing.
This works: http://www.libsdl.org/release/SDL-devel-1.2.9-mingw32.tar.gz

##### Share on other sites
OK, i found it, thanks!

but a new problem: the version of dev-c++ lazy foo used is different than mine. I can't chose all the options he described when accessing "project options".

see:

http://lazyfooproductions.com/SDL_tutorials/lesson01/windows/devcpp/index.php

##### Share on other sites
Quote:
 Original post by Anonymous PosterOK, i found it, thanks!but a new problem: the version of dev-c++ lazy foo used is different than mine. I can't chose all the options he described when accessing "project options".see:Lazy Foo's SDL tutorials

[Edited by - Lazy Foo on August 10, 2007 12:50:08 AM]

##### Share on other sites
off course..

everything is installed now, but i still can't make it work. when compiling some examples i get linker errors: undefined reference to 'SDL_RWfromfile' etc...

i added the devcpp\include\SDL directory to the C++ includes directories mentioned in the compiler options but that didn't help. do i need to do anything else or is reïnstalling the whole bunch the way to go?

greetings, T

##### Share on other sites
Quote:
 Original post by twoaterisnoff course..sorry about that, i thought i had the latest version.everything is installed now, but i still can't make it work. when compiling some examples i get linker errors: undefined reference to 'SDL_RWfromfile' etc...i added the devcpp\include\SDL directory to the C++ includes directories mentioned in the compiler options but that didn't help. do i need to do anything else or is reïnstalling the whole bunch the way to go?greetings, T

That is good and all, but you need to do this:
1) Find the libSDLmain.a and libSDL.a files and put them in your devcpp/lib directory. Then in linker options (they are to the right of the compiler options, iirc), put:
-lmingw32-lSDLmain-lSDL

2) Find and put the SDL.dll file into your .exe directory or system32 directory.... Atleast for windows this is the way.

Linking errors occur when you haven't linked the libraries, as in step 1. Then if you link but can't run the exe itself and it tells you it's missing SDL.dll it's because you didn't do step 2.

I think you have the headers right... I mean, it found the function names.
EDIT: Note: The 'l's are lower-case 'L's, not upper-case 'i's.

##### Share on other sites

I had allready done all that, but appearantly these settings (step 1) don't apply if you don't put your code in a project and just in a source file, like i did.
it's working now. not what i wanted it to do, but at least it's doing something :)

but thanx anyway!!

##### Share on other sites
I did all of that too. My IDE says that the "SDL/SDL.h" directory doesn't exist, but I've done everything the tutorial told me to do.

[Edited by - ozzoright on April 18, 2006 12:52:16 PM]

maybe SDL\SDL.h

##### Share on other sites
I have a problem using the TTF library. it gives me a runtime error on this line:

font = TTF_OpenFontIndex("arial.ttf", 16, 0);

or

font = TTF_OpenFont( "arial.ttf", 28 );

(i tried both)

this gives NULL for font, which i declared a global variable:

TTF_Font *font = NULL;

i put arial.ttf in the same directory as the .exe and using other fonts gives the same result. is there a specific folder i should put the .ttf files in?

##### Share on other sites
Quote:
 Original post by twoaterisnI have a problem using the TTF library. it gives me a runtime error on this line:font = TTF_OpenFontIndex("arial.ttf", 16, 0);orfont = TTF_OpenFont( "arial.ttf", 28 );(i tried both)this gives NULL for font, which i declared a global variable:TTF_Font *font = NULL;i put arial.ttf in the same directory as the .exe and using other fonts gives the same result. is there a specific folder i should put the .ttf files in?

Did you TTF_Init()?

##### Share on other sites
yes, this in my "bool init()" function:

if( TTF_Init() == -1 )
{
return false;
}

but it doesn't complain about the commands i'm using, it just fails to open the font.

##### Share on other sites
My error message changed after installing SDL via the Dev-C++ updater... now I have a build error.

##### Share on other sites
To both people who have problems:

Post the line that has an error, and the error messages.

[edit:]Or, better yet, if your program is under a hundred lines of code, post the whole thing with <source> and </source> tags around it. (but switch '<' '>' with '[' ']' on the tags)

##### Share on other sites
i had the same problem, try deleting the first sdl from "sdl/sdl.h".

##### Share on other sites
Still won't work... heres the code:

#include "SDL/SDL.h" //EDIT: This is the line with the error message.

int main()
{
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );

//Quit SDL
SDL_Quit();

return 0;
}

Anything wrong? I'm getting "Build Error".

Thanks.

##### Share on other sites
You have to add these parameters in the main function. int argc, char* args[]
like this:
int main(int argc, char* args[]) {

##### Share on other sites
Quote:
 Original post by passwordYou have to add these parameters in the main function. int argc, char* args[]like this:int main(int argc, char* args[]) {

And to elaborate, this is because SDL does some funky #defining and renaming to get itself to work. What happens is that your function "main" is actually renambed to SDL_Main(...).

So, when you don't specify the correct params, SDL won't know what to replace.

The only exclusion is when you compile under linux... IIRC, compiling under linux accepts just "main()".

##### Share on other sites
WOW! Works fine, no errors. Thanks guys, I really appreciate it, I had alot of trouble trying to get this thing to work. Thank you all so much! :) :) :)