Download

Question about cross platform compiling

Hi guys!

I have a question abut cross platform building. Specifically, I am making a game for Windows, Mac and Linux. I have come to a point where I need to use code that is specific to each operating system and this is causing some trouble.

In C++ is it possible to tell a compiler to look at the operating system and choose to ignore some of the code? By ignore, I do not mean comment it out, I mean just ignore it. Sorry if this is a noobish question. I have been looking on google and have not been able to find an answer.

I have looked in to pre processor directives and can successfully have my code detect the operating system but that is all I have been able to do so far.

Maybe someone with more experience might be able to point me in the right direction?

Thank you in advance!

This might help:

The article shows how to use the preprocessing directives to detect the o.s. on which you are compiling, which is not necessarily the same as the target o.s., but you can use the same general technique with the #ifdef directives. Unreal should define some macros for the build target (I don’t know those offhand), and you would simply make your #ifdef conditional logic care about the target platform rather than the build host.