Читать книгу Beginning Programming All-in-One For Dummies - Wallace Wang - Страница 86

Target platforms

Оглавление

Most compilers can compile programs only for a specific operating system, such as Linux or Windows. However, what happens if you need to write a program that runs on two or more operating systems?

You could write the program twice with two different compilers — one for each operating system. So, if you wanted to write a C++ program that runs under macOS and Windows, you could compile that program by using Microsoft Visual Studio (for Windows) and then write a similar program to compile by using Xcode (for macOS).

Of course, writing the same program two times for two different compilers on separate operating systems is a tremendous waste of time. As an alternative, some compilers are known as cross-compilers — they can create programs that work on multiple operating systems, such as Linux, macOS, and Windows. Figure 4-2 shows the Xojo cross-compiler, which lets you choose whether to compile a program for Linux, macOS, or Windows.


FIGURE 4-2: A cross-compiler lets you write a program and compile it for multiple operating systems at the click of a mouse.

With a cross-compiler, you can write a program once and compile it to run on multiple operating systems, effectively doubling or tripling your potential market. Without a cross-compiler, you may need to write a program for each compiler, under a different operating system, essentially doubling or tripling your work.

Although the idea of writing a program once and having it run on multiple operating systems may seem appealing, cross-compilers aren’t perfect. Chances are, you’ll have to tweak your program to run under each operating system, but those minor tweaks will be much easier than rewriting huge chunks of your program if you had to use two separate compilers.

Beginning Programming All-in-One For Dummies

Подняться наверх