Any help appreciated

Ok to start i just want you to know im new to c++ and im still trying to learn the basics so please don't be harsh about the question im about to ask.

Basically i was wondering when i make a c++ program what operating systems is it
compatible with or do i have to make it compatible with a certain operating system basically what im asking is this...........

say i made some random program just using basic c++ knowledge would it run and actually function on an operating system such as windows,linux,etc.


Any answers are greatly appreciated :)
Right from its inception "C", that was one of its claims to fame, being cross platform compliant. All that's really required is the version of compiler compatible with your computers architecture, be it X86, ARM, RISC, AVR etc. The fundamentals are wrapped in iostream & fstream as far as interfacing with hardware, but once you want to get more specific, such as GUI, then for windows let's say you need to use libraries specifically designed for the version of windows your using. As an example, ncurses for Linux is functionally equivalent to msvcrt for windows.

When you only use the headers supplied with compiler, it's a pretty safe bet your code will work on any computer that has monitors, disk drives, keyboards and mice or at least capable interfacing with those like the Raspberry PI. More specialized boards like Ardunio use a "C" compiler that doesn't deal with streams or io.
Thank you! :D
Just to be clear: one can't make an executable program on one OS, put it on a USB stick, then expect it to work on a different OS.

There are several things to do:

*1 Take the source code (the cpp and header files) and compile them on the other OS (Linux or Mac say). Provided there is no use of OS specific things like windows.h say, that is the code is platform independent, it should work on that system. This means one has to have a compiler / linker on that system.

*2 Cross compile the code. This means that one can compile and build on any one system like Windows say, with a target of Linux or Mac say. This is a bit more problematic, but not impossible (It's done all the time). Issues include having the right libraries and other things on the target system. Code is compiled and linked and pit into library files. It's possible to use a framework like Qt, have one code base, and target different platforms. As opposed to having different code for different platforms.

*3 Some systems like Linux have a program called Wine, which does allow an executable from windows to run in Linux. But this has limited support - it is probably not going to work for something MS Excel for example :+) So this is for fairly simple things, I am not sure but it might work for something like the Minesweeper game for example. And it is not plug'n'play there is a bit of horsing around to get it working, but support is improving all the time, allegedly.

So the big thing is to always strive to write platform independent code, stick to standard conforming c++ (c++14 currently), use standard or well known template and function libraries like the STL, Boost, Juce, Qt etc.

Good Luck !!
Topic archived. No new replies allowed.