Environment Setup
Configure your development environment for modern C++ (C++20/C++23)
Compiler Requirements
| Compiler | Minimum Version | C++20 Support | C++23 Support |
|---|---|---|---|
| GCC | 11.0+ | Full | Partial (13+) |
| Clang | 14.0+ | Full | Partial (17+) |
| MSVC | VS 2019 16.11+ | Full | Partial (VS 2022 17.4+) |
Windows Setup (Visual Studio)
# Using Visual Studio 2022
# 1. Install "Desktop development with C++" workload
# 2. Select "C++ CMake tools for Windows"
# 3. Select Windows 11/10 SDK
# Verify installation
cl.exe
# Expected: Microsoft (R) C/C++ Optimizing Compiler
# Enable C++23 in CMakeLists.txt
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)Linux Setup (GCC)
# Ubuntu/Debian
sudo apt update
sudo apt install build-essential cmake gcc-13 g++-13
# Set default compiler
export CC=gcc-13
export CXX=g++-13
# Verify
g++-13 --version
# Expected: gcc-13 (Ubuntu ...) 13.x.x
# Compile with C++23
g++-13 -std=c++23 -o program main.cppmacOS Setup (Clang)
# Install Xcode Command Line Tools
xcode-select --install
# Or install via Homebrew
brew install llvm cmake
# Use latest Clang
export PATH="/opt/homebrew/opt/llvm/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
# Verify
clang++ --version
# Expected: Homebrew clang version 17+CMake Project Template
cmake_minimum_required(VERSION 3.20)
project(cpp23_examples CXX)
# C++23 Standard
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Compiler-specific options
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/W4 /permissive-)
endif()
# Example executable
add_executable(example main.cpp)VS Code Configuration
Recommended extensions and settings:
// .vscode/settings.json
{
"C_Cpp.default.cppStandard": "c++23",
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.configureOnOpen": true,
"editor.formatOnSave": true,
"C_Cpp.formatting": "clangFormat"
}
// Recommended extensions:
// - ms-vscode.cpptools
// - ms-vscode.cmake-tools
// - twxs.cmake
// - jeff-hykin.better-cpp-syntaxQuick Test
Verify your setup with this C++23 test program:
#include <print>
#include <expected>
std::expected<int, const char*> safe_divide(int a, int b) {
if (b == 0) return std::unexpected("Division by zero");
return a / b;
}
int main() {
std::println("C++23 Environment Ready!");
if (auto result = safe_divide(10, 2)) {
std::println("10 / 2 = {}", *result);
}
return 0;
}