Hello!
Things to be aware of in my experience are:
- Write standard conformant code. You might need to use a different compiler on different platforms. C++ compilers may have their own extensions and features (e.g. pragmas) which might not work on others, or may be able to do clever things that other can't (e.g. the Microsoft compiler in my experience is sometimes less clever than GCC when it comes to template argument deduction, resulting in some code not compiling on msvc).
- Be aware of performance and availability of the c++ features you are using. Some more recent c++ features might not be supported on all compilers. Things like exception handling might be badly implemented and cause performance impacts on some compilers.
- Avoid calling platform specific code directly (e.g. windows api functions), since of course it will not work on other platforms.
- Graphics API are also platform specific. DirectX will only work under windows. OpenGL is more portable, but for mobile devices you will use GL ES, which is more constrained.
- If you use third party libraries, make sure that they are cross-platform and that they support all platforms that you are targeting.
- Pay attention to platform specific limitations. For example, on Android you will not write your own main, but you will write a library which will then be linked to the actuak executable. Another example, is that windows encodes unicode file names in the utf16 format, while linux in the utf8 format.
- If you just manage your project builds in an IDE, you might need to redefine the builds for platforms on which you can't use that specific IDE.
In general the following will help you writing platform independent code.
- Wrap third party, platform specific, and compiler specific code behind your own interfaces. In this way, you can swap things out or support new platforms without changing the code built on top. You just need to write a new implementation for your interfaces.
- Continuously test builds in all target platforms. This will let you notice problems immediately, when they can be fixed without too much effort.
- If possible, use a library that abstracts the underlying platforms for you. This will save you a lot of time. SDL is very good and widely used. GLFW is ok as a windowing only library, but you will need something else for mobile platforms. SFML is a c++ style library, but I feel it is a bit more limited than SDL. I am also working on my own c++ middleware library (https://github.com/DavideCorradiDev/houzi-game-engine), which is partly built on top of SDL, but it is not mature yet. :)
- Use a cross-platform build system, e.g. cmake. In this way you can manage builds for all target platforms in one place.
- Figure out early what platforms you want to support, or you might have to make large redesigns later.
- Figure out early what your game needs. Swapping from 2d to 3d graphics for example might not be a light undertaking. :)