Sign in to follow this  
WazzatMan

Rules of Thumb when using C++ to develop multiplatform code

Recommended Posts

I'm starting a project in C++, and I'm hoping to create linux and mac distributables for it once the project is finished. It's not really a priority, but if it's as simple as how I think it is, then it shouldn't be a problem. My assumption is that I'd have to use ISO standard C++ code, and libraries specifically written to be multi platform (Like SDL). Then I'd recompile the code using a specific os compiler et viola. Something tells me it's not that simple.

Share this post


Link to post
Share on other sites
Quote:
Original post by WazzatMan
I'm starting a project in C++, and I'm hoping to create linux and mac distributables for it once the project is finished. It's not really a priority, but if it's as simple as how I think it is, then it shouldn't be a problem.

My assumption is that I'd have to use ISO standard C++ code, and libraries specifically written to be multi platform (Like SDL). Then I'd recompile the code using a specific os compiler et viola.

Something tells me it's not that simple.
It should be, and if your coding practices are good, it will be.

However, Microsoft headers/compilers have a particularly nasty habit of auto-including a bunch of platform-specific stuff, so make sure that you are actually writing std c++.

Also be aware that if you want to run your program on older PowerPC based macs, you will need to take endianess into account when reading and writing files.

Share this post


Link to post
Share on other sites
Off the top of my head:

- Be careful with byte-endian-ness.
- Get your game building on at least one platform as soon as possible.
- If you don't have hardware for other platforms available yet, then being able to build your project with multiple compilers (VS and GCC) will help.
- You are going to have to write platform-specific code sooner or later, so figure out how you're going to keep that organised from the start, instead of having #ifdefs scattered everywhere.
- Unit tests for platform-independant code can go a long way to ironing out platform-specific bugs in lower level libraries and code.

Consider embedding a scripting language like Python or Lua for gameplay code which should work the same regardless of the underlying platform.

Share this post


Link to post
Share on other sites
Quote:
However, Microsoft headers/compilers have a particularly nasty habit of auto-including a bunch of platform-specific stuff, so make sure that you are actually writing std c++.


I'm using minGW and codeblocks, so Microsoft headers shouldn't be a problem.

Quote:
If you don't have hardware for other platforms available yet, then being able to build your project with multiple compilers (VS and GCC) will help.


I've downloaded virtualbox and I was thinking of using it for testing the game's compatibility with linux. That should give the same results as a linux machine, right?.

Thanks for the help :).

Share this post


Link to post
Share on other sites
Quote:
Original post by WazzatMan
I've downloaded virtualbox and I was thinking of using it for testing the game's compatibility with linux. That should give the same results as a linux machine, right?.


Yep, that's what I do. It works well :-)

Share this post


Link to post
Share on other sites
Quote:
Original post by WazzatMan
Quote:
However, Microsoft headers/compilers have a particularly nasty habit of auto-including a bunch of platform-specific stuff, so make sure that you are actually writing std c++.

I'm using minGW and codeblocks, so Microsoft headers shouldn't be a problem.
Still worth compiling your code with VS once in a while - compiling with multiple, different compilers (both in strict mode) helps to catch a lot of non-standard code.

Share this post


Link to post
Share on other sites
Definately compile it now and then with gcc. It seems to be the strictest to the c++ standards and catches some things other compilers will let you get away with.
Also get the different platforms up and running ( or find people here on gamedev to test for you - or use a VM ).. as there's bound to be quirks on each one that you'll need to address. Test on these platforms as you go, instead of just developing it all in windows and expecting it to work when your done.

Share this post


Link to post
Share on other sites

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