Skip to main content
GameDev.net gamedev.net
🔒 Locked

Need Help Setting Up SDL

Started by Aluthreney Jan 16, 2012 at 11:21 PM 7 replies 1.5k views
Original Post
Aluthreney
Aluthreney
I'm want to start working with SDL, but I need help setting it up. I'm working on Ubuntu with the CodeBlocks IDE. From what little information I was able to gather, (in Codeblocks) I went to Settings -> Compiler and Debugger -> Search Directories. Under the "Compiler" tab I wrote: /usr/include. Under the "Linker" tab I wrote: /usr/include/SDL. When I compile my program the only error I get is: undefined reference to 'SDL Function', so I think I setup the library correctly because it's not giving me the usual "no such file or directory" error, but I don't know. Can anyone explain what I did wrong (or didn't do)?
Aluthreney -- the King of sheep.
Wil Turner
Wil Turner
I'm working in Windows 7, but here's the idea: the "compiler" tab should have the folder containing SDL.h, which is the "include" folder. The "Linker" tab should have the folder containing "SDL.dll", which is the "lib" folder.

Also, make sure in the build settings, in the "Link Libraries" spot, you've added mingw32, SDL_main, and SDL, along with any other libraries you plan on linking.
Aluthreney
Aluthreney

Also, make sure in the build settings, in the "Link Libraries" spot, you've added mingw32, SDL_main, and SDL, along with any other libraries you plan on linking.


Isn't mingw32 only used in windows OS?
Aluthreney -- the King of sheep.
Wooh
Wooh
undefined reference is a linker error. Maybe you can add this to your linker options?`sdl-config --cflags --libs`
Aluthreney
Aluthreney
I was able to fix the "undefined reference" error, but now I have a new one: cannot find -lsdl_main? What did I do wrong now?
Aluthreney -- the King of sheep.
Wooh
Wooh
It should be -lSDLmain, but I don't think it makes any difference on Linux.
Aluthreney
Aluthreney

Also, make sure in the build settings, in the "Link Libraries" spot, you've added mingw32, SDL_main, and SDL, along with any other libraries you plan on linking.


I just solved the problem! You were telling me to add SDL_main and SDL to my link settings, but SDL already invokes SDL_main. SO I deleted SDL_main from my link setting and the errors went away. However, the image that's supposed to appear isn't appearing, but I think that because its saved as a .jpg instead of .bmp.
Aluthreney -- the King of sheep.
Wil Turner
Wil Turner

I just solved the problem! You were telling me to add SDL_main and SDL to my link settings, but SDL already invokes SDL_main. SO I deleted SDL_main from my link setting and the errors went away. However, the image that's supposed to appear isn't appearing, but I think that because its saved as a .jpg instead of .bmp.


Great! I recommend, if you want to use jpg, png, or other image types (yay alpha transparency), get SDL_image! Everything works exactly the same, except you use IMG_Load(char* file) instead of SDL_LoadBMP(char* file), and you use SDL_DisplayFormatAlpha() instead of SDL_DisplayFormat().
Wil Turner
Wil Turner
Note, SDL_image adds the ability to handle transparency and other image types, but you still use all of SDL functions that you would have used before!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.