Some programs, you might just be able to recompile for a new platform, no problems. If it's a very simple program, not using anything specific to that OS, you might be able to get away with this. Basically, taking the source, moving it to another OS, and using a compiler on there. Even if there is specific code, though, you could use compile-time flags, or constants in your code, to get the compiler to operate differently. I'm rusty on my C++ syntax, but I think this should show what I mean:
#if OS == WINDOWS
root = "C:\\";
#elseif OS == LINUX
root = "/";
#endif
Another method is to run the program inside a virtual machine, like Java. That VM would work on different platforms, and your executable should be able to run seamlessly across anything using it. You may have to do a recompile with a few small changes, if there was OS-specific code, but if you're intending from the start to port, then you likely wouldn't worry about this.
A third way is a combination of the two, and is, if I recall correctly, what Firefox does. Most of the code stays exactly the same, but it uses a base to run on, which is compiled specifically for that OS, that defines different things, creates specific types of variables, such as nsInt
(been awhile since I've looked at FF code, so I'm likely wrong, but I know prepending ns
is their convention) which you would use in place of int
, as it would specifically be designed to be the same across platforms.
When you compile, the correct platform is chosen for the base, then the entire program is compiled using that.