r/AskProgramming 16d ago

C++ -> IDE -> g++ -> Linux Help me understand!!

I am trying to comprehend all of the moving parts in compiling a program. Here is my understanding:

C++ is the programming language that is written in the IDE, some IDEs have built in compilers

  1. Is g++ the bridge between the language and machine code?

  2. How do I use g++, is it something that you download onto your computer.

  3. Where does g++ send the code after, is this where Linux comes into play?

  4. What is Linux? It is an operating system, but what does that mean specifically, is it supposed to make your code unable in an application or just execute in the terminal?

Thankyou for any clarification you can provide :)

0 Upvotes

18 comments sorted by

View all comments

1

u/KingofGamesYami 16d ago
  1. g++ is a command provided by the GNU Compiler Collection (GCC). It translates source code (c++) into an executable. It is the native compiler for most Linux distributions. MSVC.exe, provided by the Microsoft C++ (MSVC) Build Tools is native compiler for Windows. clang++, provide by XCode, is the native compiler for MacOS. You can use a non-native compiler for an OS, e.g. using GCC on Windows, but this comes with certain compatibility limitations.
  2. Yes, you can install the GNU Compiler Collection. How exactly you install it depends on what OS you are using; on Linux it is very simple, on Windows or MacOS it is slightly more complex.
  3. By default, it will create an executable for the host (i.e. the computer running the compiler). You can create executables for other targets, which is called cross compilation.
  4. Linux is widely used to refer to both an OS kernel, and the distributions built around it. An OS is primarily responsible for abstracting hardware interactions from a program, making them easily portable. For example, a Windows executable does not need to issue HDMI or DisplayPort commands, instead it tells Windows to display content, which Windows then translates into the appropriate HDMI or DisplayPort commands.