Hello guys I have a pretty complicated question I guess but I need to know how this all works,sorry if this post is long,
anyway so I have been programming on windows now for almost two years mainly using codeblocks as my IDE with gcc mingw as my compiler,I have gotten used to using libraries such as iostream,fstream,cstdlib, etc
but as mentioned I have been using them on windows and not linux,I have decided to move over to Linux just yesterday and installed qtCreator with mingw as my compiler,anyhow my question is how does it all work?
for example I heard that when you compile code on a windows machine it will only work for windows,and when you compile code on a linux or mac it will only work on those operating systems,so are the libraries the same??
is iostream for windows the exact same code as the iostream for linux?? or is the code different under the hood? in other words is the iostream,fstream,cstdlib used in windows the same iostream,fstream,cstdlib used in Linux or mac?
or are they the same libraries and just compiled into different source code,
the reason why I am asking this is because lets say standard output such as cout , when using cout wouldn't standard output be implemented differently on a windows machine in contrast to a unix machine??
**edit
maybe there is a macro #define that finds out if an OS is windows and runs windows code and a define macro that finds out if it is a Linux OS and runs the linux version?
compiled code is not portable.
how it works is that the compiler turns your text code (c++ files) and correct libraries (compiled code for the current OS/hardware) into machine instructions that can interact properly with the OS and hardware. When you move this, it is no longer correct for the new OS and hardware, and will not run, or worse, will actually damage your machine (I lost a silicon graphics box to this, an intern put a Linux program on it, had to format and reload the whole machine).
There are programs out there that can allow you to use the wrong program on your OS/hardware, they basically put a layer in between an convert the wrong format to the right format (this is slow). That is how a lot of Linux people play windows games, with some success and a lot of agony (a lot of stuff does not work right, but simpler programs work great with this). You can also move it to a virtual machine, which does the same thing conceptually only better (but still slow, still an extra layer between the code and the real hardware).
no, iostream is different for each OS.
In some cases its the same source code, and in other cases, for low level things (console IO may be low level, probably is) they may be total rewrites that just do the same thing when called but do it very differently inside. Something like new and delete may be radically different, while vector<> may be identical, or things in <algorithm> are probably mostly identical.
yes, macros can be used to compile something like g++ for each target machine. Or the make files can be configured for it. Or you can download working copies without worrying about it. Back when I always wrote in visual studio and had a macro or two for when we moved to Linux. You have to in a few cases .. unix has an std, and windows has cornholio.h or whatever it is.