Compiler

This page mainly introduces the installation steps for various compilers/interpreters on different systems.

GCC

Windows

Manual download and installation

Visit the MinGW-w64 download page, which offers multiple builds. For convenience, we use a build provided by WinLibs.

First, go to WinLibs to download the latest package. Choose an appropriate version; this article uses GCC 12.3.0 + LLVM/Clang/LLD/LLDB 16.0.4 + MinGW-w64 11.0.0 (UCRT):

LLVM Clang is included by default. If you do not want to install it, you can choose the "without LLVM/Clang/LLD/LLDB" option on the right.

Figure: compiler1

After downloading, extract it to a location on your computer. In this tutorial, it is extracted to the root directory of the C drive. It is best for the directory name not to contain non-English characters or spaces, otherwise this may cause problems later.

Figure: compiler2

Next, we need to add the directory containing the compiler's executable files to the system environment variables, so that we do not need to specify the compiler path when compiling. Above, we extracted MinGW to the C:\mingw64 directory, so the directory containing the executable files is C:\mingw64\bin.

Press the Windows logo key + R, enter rundll32.exe sysdm.cpl,EditEnvironmentVariables, open the system environment variable settings window, select the variable named "Path" in the "System variables" section, and then click the "Edit" button:

Figure: compiler3

In the edit window, click the "New" button on the right to create an entry for the "Path" variable, and enter the directory containing the executable files recorded above (in this tutorial, C:\mingw64\bin).

Figure: compiler4
Note for some older system versions

Some older system versions only allow you to manually modify the text value of the variable. In that case, insert a half-width semicolon at the end of the variable's value, then paste the directory containing the executable files after this half-width semicolon, as shown in the figure:

Figure: compiler5

After that, keep clicking the "OK" button to exit.

Next, open a terminal, enter g++ --version, and press Enter. If a message like the one shown in the figure appears, the installation was successful.

Figure: compiler6

Scoop installation

Open PowerShell and run the following script:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex
scoop install mingw-winlibs

Linux

Debian/Ubuntu

First update the package list:

sudo apt update

Then install it directly with the command:

sudo apt install g++

Arch Linux

Install it directly with the command:

sudo pacman -Syu gcc

openSUSE

Install it directly with the command:

sudo zypper in gcc-c++

macOS

First update the package manager:

brew upgrade
brew update

Then install it directly with the command:

brew install gcc

JDK

There are many JDK distributions. Two of them are introduced below:

Python 3

There are also many Python implementations2. Taking CPython 3 as an example, see Download Python | Python.org.

LLVM

Windows

A pitfall of LLVM on Windows

Because LLVM lacks a standard library on Windows, you still need to install MSVC or GCC.

Direct installation

Visit the LLVM download page and choose LLVM-*-win64.exe to download.

If your network quality is poor, you can instead visit the Tsinghua University Open Source Software Mirror to download it.

Open the .exe file, check Add LLVM to system PATH for current user during installation, and keep clicking Next to complete the installation.

Open a terminal, enter clang++ --version, and press Enter. If output similar to the following appears,

clang version 15.0.1
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: <omitted>

it indicates success.

Scoop installation

Open PowerShell and run the following script:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
irm get.scoop.sh | iex
scoop install llvm

Linux

openSUSE

Install it directly with the command:

sudo zypper in llvm clang

MSVC (Visual Studio)

Visit the Download Visual Studio page. Find the "Community" section under "Downloads" and click "Free download". After the download is complete, open the installer and select "Community 2022 installation". In the window that then pops up, select only "Desktop development with C++", and then click Install.

If you do not want to install the complete Visual Studio, scroll down to the "All downloads" section and find "Visual Studio Build Tools" under "Tools for Visual Studio", then click "Download" next to it. After the download is complete, open the installer and follow the prompts to select "Desktop development with C++" and install it. You can also use the PortableBuildTools tool to install only the MSVC compiler.

Footnotes

  1. Eclipse Temurin is the former AdoptOpenJDK, which was transferred to the Eclipse Foundation in July 2021. See this statement for details. ↩

  2. Alternative Python Implementations | Python.org ↩

This content comes from OI Wiki: Compiler. See the original for authors and revision history. AIOJ has adapted the formatting, in-site links, and resource paths.

Content is shared under CC BY-SA 4.0 and SATA license; additional terms are governed by the original notice. Thanks to the OI Wiki authors and contributors; per the SATA terms, please visit the OI Wiki repository and star it to show your support.