How to create C++ applications that are compatible for Windows, Linux and MacOS?
Tuesday, July 19th, 2011 at
12:11
Hi,
I am getting into C++ programming but I was wondering. What do I have to do to make sure that my C++ applications are compatible for all the popular Operating Systems? Do I have to do something different to my code or use a different compiler?
I am using Code::Blocks now.
Thanks
Tagged with: c applications • c programming • code blocks • popular operating systems
Filed under: Linux Applications
Like this post? Subscribe to my RSS feed and get loads more!
I developed some game apps (Suduku, TicTacToe) under Windows using Qt. Qt is a graphics "middleware" that works using C++ extensions. I was able to run them on a Linux based bank card terminal, as well as Windows. I have not a Mac at my disposal so I have not gone there, but I do know that Qt runs on a Mac. I have not yet tried building the apps for PC Linux.
To answer your question:
Use Qt and/or the GCC(C++ compiler) to develop your apps.
Qt will run on Windows, Linux, or Mac.
GCC will run on Linux, or Mac. To run it on Windows you need Red Hat Cygwin.
http://en.wikipedia.org/wiki/Qt_%28framework%29
http://en.wikipedia.org/wiki/Cygwin
I know all this sound complicated, but it is not all that bad once you read up on the respective envornments.
Good luck
There are a few ways to do it.
1: Be very careful and don’t use any operating system specific calls. In other words, it becomes a command line program and text interface. You still have to compile it for each operating system and there still may be some operating system specific calls that must be included for each. That is what make files are for. This solution is totally free. It also has the advantage of not needing to distribute executables for all operating systems. You can just distribute one set of source code.
2: Use an emulator on 2 of the 3 operating systems. One program compiled for one operating system. This has it’s own problem of requiring an emulator that is capable of running your program. If you get to deep into Windows, it might not work completely on other operating systems. Free emulators are generally available for Linux and MacOS.
3: Use a universal library. There are some libraries available that streamline writing universal code for more than one operating system. Several are Linux and Windows compatible, but it might be difficult to find something that will work with all three. Using such a library will bring with it another set of difficulties mostly associated with the limits of the library. This solution is the most likely to have some sort of cost associated with it.
4: You could write operating system specific code which would require access to the operating systems to test them. This is probably the worst choice because you’d have to make changes to 3 different source code sets and it would be easy to get things jumbled.
C and C++ are supposed to be "portable" between operating systems. A major problem is they have severe limits. You have to decide which way you want to go and if it is really worth it to maintain a program compatible with more than one operating system.
Shadow Wolf
You would need to use a cross platform compiler.
Write it in Java. That’s the one (and only thing Java does well.
Or, like Shadow Wolf said, write a simple command line based app, they tend to be more portable. And about 1% of the users in the world are still quite happy to use a command line based application.
The QT framework might be another choice. Never used it, but I’ve seen it used with some success on another project, and heard reasonably good things about it. See link.