🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Cross platform compiling (SDL)

Started by
12 comments, last by Grellin 19 years, 9 months ago
I have been using SDL for a while now on Windows and although I know it is a cross platform API, I had never actually tried. Needless to say I was shocked when it actually worked. I cut and pasted some of my code from Windows MSVC++ 6 to Fedora Core 2 using KDevelope and it compiled and executed flawlessly. I don't know why I was shocked since everything else I have read about SDL has been true, but I was. Anyway, I decided to start making all of my projects for Windows and Linux and had a question for those who may already do that. What are some of the pitfalls I should try to avoid? I will continue to explore this new world of possibility but any heads up would be appreciated.
Steven Bradley .:Personal Journal:. .:WEBPLATES:. .:CGP Beginners Group:. "Time is our most precious resource yet it is the resource we most often waste." ~ Dr. R.M. Powell
Advertisement
You've got half the battle won using SDL. That shields you from having to do the windowing, input, sound, etc. The only things that might be problematic is if you're used to the Windows API only. Linux, for example, doesn't have one of those pretty "find directory" dialogs via API. You'll have to code something like that yourself.

Just stay away from those sorts of things and you'll be OK. SDL does the hard work for you :).
I've not tried VS.net yet, but if you're using VS6 you may find one or two issues with the C++ standard bite you from time to time. A common one for me is
for(int x = 0; x < 2; ++x) { blah(); }
for(int x = . . .
which is fine in C++ but VS6 doesn't like it.

um ... actually, everything else I've done so far just works, so long as you stick with C++. If you start doing old fashioned C things you end up needing different headers (unistd.h etc).

Stick with SDL for timing issues because that's one area that different OS's try to be as incompatible as possible on.
If you want to load DLLs (or SOs on Linux), then you'll have to write your own code. If you keep all code in one main program you won't have this problem though.
Its great isnt it? When I compiled my pong clone on linux it worked perfectly.
______________________________________________________________________________________With the flesh of a cow.
Thanks for the replies. This is really working out better than I imagined. At this point I haven't noticed any difference in performance but I am only using 2d for now. Soon to try incorperating OpenGL with it.

Steven Bradley .:Personal Journal:. .:WEBPLATES:. .:CGP Beginners Group:. "Time is our most precious resource yet it is the resource we most often waste." ~ Dr. R.M. Powell
Something i see ALOT of people doing wrong in SDL is not using the SDL defined typedefs that wrap over the normal data types (like Uint32 and Sint8).
Now I get a cookie!
i dont understand the purpose of using the SDL data types in replace of char, int, or short... what IS the point exactly? is it for enianess purposes? and where is the SDL float and double ?
FTA, my 2D futuristic action MMORPG
Quote: Original post by graveyard filla
i dont understand the purpose of using the SDL data types in replace of char, int, or short... what IS the point exactly? is it for enianess purposes? and where is the SDL float and double ?

DISCLAIMER: Might not be accurate.

Yep its for diffrent machines. Since mac is big endiean and pc is little endian some data types are diffrent.
______________________________________________________________________________________With the flesh of a cow.
ok, but, i dont understand.... if i compile my source on a mac, and a mac user runs the program, wont it work fine if i used int, long, short, etc?? i mean, since i compiled (or even just executed) it on a mac, wouldnt it know that i wanted mac endianess? i mean, i doubt theres some sort of macUint8, right? im guessing they call it int too ? so, why even bother?

the only situation i see a problem is in a cross platform networked game. in which case you should be converting from / to host / network byte order when sending / receiving anyway.
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement