-
Notifications
You must be signed in to change notification settings - Fork 0
Compiler Installation Guide
This guide will walk you through installing C/C++ compilers on different operating systems. Please choose the installation method corresponding to your operating system.
- Installing GNU GCC Compiler on Linux
- Installing Apple Clang Compiler on MacOS
- Installing Visual Studio Build Tools on Windows
- Installing w64devkit Toolchain on Windows
On Linux systems, you can directly use the following commands to install the corresponding build tools:
For Linux systems, all you need to do is install the corresponding build tools.
You can directly use the following commands to install the corresponding build tools:
sudo apt update
sudo apt install build-essential cmake ninja-build -yYou can directly use the following commands to install the corresponding build tools:
sudo dnf install cmake ninja-build -y
sudo dnf group install "development-tools" -yIf you cannot install using
dnf, please useyumdirectly. This may only be necessary on older systems.
You can directly use the following commands to install the corresponding build tools:
sudo pacman -Syu
sudo pacman -S cmake gcc g++ gdb make ninja-buildOn MacOS, please first install the basic command line tools through the following command:
xcode-select --installThis will pop up a dialog box. Please follow the prompts to download and install it online.
You can use the homebrew package manager to install the corresponding build tools. You only need to execute the following commands in the terminal to complete the installation:
# Download and install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install build tools
brew install cmake ninja-build clang llvm❗ Notes:
For MacOS Monterey 12 and below, it is not recommended to use Homebrew to install build tools, as it will take too long to download and compile the build tools, and there is no 100% guarantee of successful installation.
You can also use the MacPorts package manager to install the corresponding build tools.
First, you need to download and install the package from the MacPorts official website (download according to different versions). The downloaded installation package is usually in *.pkg format.
If you have already completed the installation, please open a new terminal window and execute the following command in the terminal to confirm whether MacPorts can be used in the terminal.
port --versionAfter that, you need to update MacPorts and install the corresponding build tools. Here we will take installing the clang-16 version of the build tools as an example:
sudo port selfupdate
sudo port install cmake ninja clang-16 llvm-16 lldb-16🖊 Tips:
Regarding the choice of Clang compiler version, you can choose to install
clang-17,clang-18,clang-19, and so on.You can check all available Clang compiler versions through
port search clang | grep ^clang-.For example: To install clang 21 version and its toolchain, you need to execute the following command:
shell sudo port install cmake ninja clang-21 llvm-21 lldb-21
After the installation is complete, you can check the files in the /opt/local/bin/ directory to confirm whether the corresponding build tools are installed successfully.
ls /opt/local/bin/ | grep cmake
ls /opt/local/bin/ | grep ninja
ls /opt/local/bin/ | grep clang
ls /opt/local/bin/ | grep lldbThe output may look like this:
ccmake
cmake
ninja
clang++-mp-16
clang-apply-replacements-mp-16
clang-change-namespace-mp-16
clang-check-mp-16
clang-cl-mp-16
clang-cpp-mp-16
clang-doc-mp-16
clang-extdef-mapping-mp-16
clang-format-mp-16
clang-include-cleaner-mp-16
clang-include-fixer-mp-16
clang-linker-wrapper-mp-16
clang-move-mp-16
clang-mp-16
...
Or you can directly check through the following command in MacPorts:
port list installedFinally, you also need to configure system environment variables so that you can directly use the corresponding build tools in any terminal. Here we assume you have installed the clang-16 version of the build tools. If you have installed other versions, please replace 16 with your actual main version number. Please execute the following commands in the terminal:
cat >> ~/.zshrc << EOF
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
alias clang="clang-mp-16"
alias clang++="clang++-mp-16"
alias lldb="lldb-mp-16"
...
EOF
source ~/.zshrcAfter execution, please restart the terminal and re-execute the command to check if the installed version is the one you installed.
clang --version
clang++ --version
lldb --version
Download Visual Studio Build Tools. After downloading, launch the installer.
You can directly select Desktop development with C++ in the Workloads tab to install.
If you prefer a minimal installation, you can only install the following components in the Individual components tab:
- MSVC v143 - VS 2022 C++ x64/x86 Build Tools...
- MSVC Build Tools for x64/x86 (Latest version)
- Windows 11 SDK (10.0.26100.6901)
- MSVC AddressSanitizer
After installation is complete, you can usually find the [Visual Studio 2026] folder in the Start menu. After expanding it, you will find programs similar to the following:
- x64 Native Tools Command Prompt for VS
- x64_x86 Cross Tools Command Prompt for VS
- x86 Native Tools Command Prompt for VS
- x86_x64 Cross Tools Command Prompt for VS
You can download and install the w64devkit toolchain.
After installation, you only need to configure the system environment variables so that you can directly use the MinGW compiler build tools in any terminal. The specific script is as follows:
$mingw64Path = "\path\to\w64devkit"
$newPath = "$mingw64Path\bin"
$currentUserPath = [Environment]::GetEnvironmentVariable("PATH", "User")
[Environment]::SetEnvironmentVariable("PATH", "$currentUserPath;$newPath", "User")
$env:PATH = [Environment]::GetEnvironmentVariable("PATH", "User")Where $mingw64Path is the path to the w64devkit toolchain you downloaded and installed.
Replace $mingw64Path with your actual installation path.