Are programs encoded separately for different operating systems?

If the program was written in C ++ to run on Windows, do you need to completely rewrite it to work on Mac OS or mobile OS?

+4
source share
5 answers

C ++ is a standard language, which means that the source code you write can be compiled on any platform that has an implementation of the C ++ standard. There are two ways to write C ++ programs that cannot be compiled for different implementations. Firstly, if you use language extensions that are only in a specific (set) of implementation (s). Secondly, the use of a library, which depends on code that is not supplied with the standard library (for example, in the OS API).

For the first question, always try to write standard code. For the second, use cross-platform libraries such as Boost, Qt ...

+5
source

As a rule, yes, because the program will need to use OS-specific functions for windows and, possibly, for other functions (network interaction, synchronization, etc.). However, many programs try to minimize this by creating shell classes, so most of the program is associated with these wrappers, and not with raw tools for a particular platform. To transfer a program from one platform to another, you just need to redefine the shell using the new platform tools.

Many programs do this even further, using pre-written libraries like Qt or Boost to handle some cross-platform stupidities, but this is (essentially) the above idea on a larger scale.

+4
source

It depends. In general, Standard C ++ is a universal, portable language that can be compiled to work on any system or platform that has a standard compiler.

However, many more interesting features that you can add to a typical application are not part of Standard C ++. This includes graphical interfaces, threads, sockets, and low-level OS API calls. They are usually not portable, and the parts of the code that use these functions must be implemented separately for each operating system or platform.

Fortunately, it is not as difficult as it seems, because there are many cross-platform libraries that have already survived this problem. For example, the Boost threading library already has code for streaming written for different platforms or operating systems, but all this is abstracted for a good uniform API that can be used portable in the C ++ application code.

In addition, a lot of non-standard C ++ code still complies with some standard, for example POSIX , which is supported on several platforms.For example, most UNIX-ish systems, including Linux and Mac OS X, support POSIX streams (pthread API )

+3
source

If the code itself uses libraries that are supported on all target platforms, you only need the appropriate compilers to create a valid binary for each system.

+1
source

The software can be written in several languages ​​and then linked together. For example, I can encode the internal logic of my application in C ++ (often using Boost), and then create two separate interfaces in C # for Windows and Objective-C for Mac. I can link the C ++ and C # components to send to the same platform, and then link the C ++ and Objective-C components to send to the other. This approach will give the most β€œown” appearance for each platform.

Alternatively, I can code the entire interface in C ++ using Qt or WxWidgets. This will work on all platforms, although without 100% of the speakers and platform whistles.

+1
source

Source: https://habr.com/ru/post/1334297/


All Articles