C++ Development Environment Setup: From Compiler Install to Hello World

C++ Development Environment Setup: From Compiler Install to Hello World

이 글의 핵심

Install MSVC, MinGW (GCC), or Xcode (Clang), then build and run your first C++ program on Windows, macOS, or Linux—step by step.

[C++ Hands-On Guide #1] Setting Up a C++ Development Environment

Previous: Guide #0: What is C++? covers history, ecosystem, pros/cons.

Requirements: Windows, macOS, or Linux with MSVC, MinGW (GCC), Xcode (Clang), or system packages (g++, build-essential). No extra libraries are required for Hello World.

After this article: You can install a compiler on your OS and run a first program end to end.

To learn C++, start by installing a toolchain. This guide walks through Windows, macOS, and Linux. At first, “install one compiler and run g++ once in a terminal” is enough. IDEs and build systems (CMake #4) are covered later—the goal here is turning a .cpp file into an executable.

Table of contents

  1. Common problem scenarios
  2. Why the environment matters
  3. Compiler selection guide
  4. Windows setup
  5. macOS setup
  6. Linux setup
  7. First program
  8. IDE setup (VS Code, Visual Studio)
  9. Build tools (Make, CMake basics)
  10. Online compilers
  11. Common errors
  12. Best practices
  13. Troubleshooting
  14. Production tips

1. Common problem scenarios

1) “g++ is not recognized”

Cause: Compiler not installed, or PATH does not include the compiler bin directory (common on Windows after MinGW/MSYS2).

Fix: See Windows setup for PATH.

2) “Visual Studio is too heavy”

Cause: VS bundles IDE, debugger, and SDKs (multi‑GB install).

Fix: Use MinGW via MSYS2 for a lighter GCC toolchain, or WSL for Linux g++.

3) “cl is not recognized” (MSVC)

Cause: cl only works in a Developer Command Prompt or after vcvarsall.bat sets the environment.

Fix: Start Developer Command Prompt for VS from the Start menu.

4) “iostream not found”

Cause: Using gcc instead of g++, wrong standard flags, or broken include paths.

Fix: Use g++ and add -std=c++17 (or newer) as needed.

5) “On macOS, g++ shows Apple Clang”

Cause: g++ is often a symlink to Clang. That is normal—use Clang for development on macOS.

6) “Local build works; CI fails”

Cause: Compiler version, standard flags, or platform-specific libraries differ.

Fix: Pin toolchain versions; see Production tips.

7) “Missing libgcc_*.dll” (MinGW)

Cause: Runtime DLLs not beside the .exe or on PATH.

Fix: Add C:\msys64\mingw64\bin to PATH, or link statically (-static-libgcc -static-libstdc++) when distributing.

8) “VS Code IntelliSense is broken”

Cause: Wrong compilerPath in c_cpp_properties.json.

Fix: See IDE setup.


2. Why the environment matters

C++ is compiled: unlike Python or JavaScript, you must run a compiler to produce a native binary. After you edit code, recompile to see changes.

Three pillars:

  1. Compiler — translates source to machine code (GCC, Clang, MSVC).
  2. Build tools — scale to many files (CMake is the common cross-platform choice).
  3. Editor/IDE — edit, navigate, debug (VS Code, Visual Studio, CLion, …).

This article focuses on installing the compiler first; editors and CMake plug in once the toolchain is known. See #4 CMake and #3 VS Code for wiring paths to g++ / clang++.

flowchart LR
    A[Source .cpp] --> B[Preprocessor]
    B --> C[Compiler]
    C --> D[Assembler]
    D --> E[Linker]
    E --> F[Executable]

3. Compiler selection guide

CompilerOSNotes
MSVCWindowsBest VS integration; strong Windows debugging
GCCLinuxUbiquitous; excellent standards support
ClangmacOS / cross-platformFast compiles; excellent diagnostics

Windows: MSVC for Windows-only/DirectX stacks; MinGW to mirror Linux/CI with g++.
macOS: Clang via Xcode Command Line Tools.
Linux: GCC via build-essential.


4. Windows setup

Option A — Visual Studio (MSVC)

  1. Download Visual Studio Community from visualstudio.microsoft.com.
  2. Select workload “Desktop development with C++” (MSVC, Windows SDK, optional CMake tools).
  3. Open Developer Command Prompt for VS 2022 and run cl to verify the toolchain is on PATH.

Quick test:

cd %USERPROFILE%\Desktop
cl /EHsc hello.cpp
hello.exe

Option B — MSYS2 + MinGW (GCC)

  • Install from msys2.org.
  • In the MSYS2 terminal, run pacman -Syu (possibly twice), then install the toolchain:
pacman -S mingw-w64-x86_64-gcc
  • Add C:\msys64\mingw64\bin to PATH (System Properties → Environment Variables). Open a new CMD/PowerShell and verify:
g++ --version

Optional: pacman -S mingw-w64-x86_64-gdb mingw-w64-x86_64-make

Option C — WSL (Ubuntu + g++)

wsl --install

Then inside Ubuntu:

sudo apt update && sudo apt install build-essential
g++ --version

Use Remote - WSL in VS Code for a smooth edit-on-Windows, build-on-Linux flow.


5. macOS setup

xcode-select --install
clang++ --version
g++ --version   # usually Clang

Full Xcode

Install from the Mac App Store if you need iOS/macOS app tooling; select the toolchain with xcode-select -s if required.

Real GCC (optional)

brew install gcc
# often g++-13 etc.; default g++ may still be Clang

6. Linux setup

Debian/Ubuntu

sudo apt update
sudo apt install build-essential cmake gdb
g++ --version

Fedora / RHEL

sudo dnf groupinstall "Development Tools"
sudo dnf install gcc-c++

Arch

sudo pacman -S base-devel

Alpine

apk add build-base

7. First program

Create hello.cpp:

// After paste: g++ hello.cpp -o hello && ./hello  (MinGW/macOS/Linux)
#include <iostream>

int main() {
    std::cout << "Hello, C++!" << std::endl;
    return 0;
}

MSVC (Developer Prompt):

cl /EHsc hello.cpp
hello.exe

GCC/Clang:

g++ -std=c++17 hello.cpp -o hello
./hello

8. IDE setup

  • VS Code: Install C/C++ (Microsoft). Set compilerPath in .vscode/c_cpp_properties.json. See #3 VS Code.
  • Visual Studio: File → New → Console App; set C++ standard in project properties; Ctrl+Shift+B to build, F5 to debug.

9. Build tools (basics)

Makefile (Linux/macOS):

CXX = g++
CXXFLAGS = -std=c++17 -Wall -Wextra -g
app: main.cpp utils.cpp
	$(CXX) $(CXXFLAGS) main.cpp utils.cpp -o app

CMake (cross-platform) — see #4:

cmake_minimum_required(VERSION 3.10)
project(MyApp)
set(CMAKE_CXX_STANDARD 17)
add_executable(myapp main.cpp utils.cpp)
mkdir build && cd build
cmake ..
cmake --build .

10. Online compilers

Use Wandbox, Compiler Explorer, OnlineGDB, or cpp.sh for quick experiments. For real projects, prefer a local toolchain.


11. Common errors (summary)

  • g++: command not found → install compiler / fix PATH.
  • iostream: No such file → use g++, not gcc.
  • cl not found → use Developer Command Prompt.
  • Permission deniedchmod +x (Unix) or run .\app.exe correctly on Windows.
  • undefined reference → link all .cpp / libraries.
  • bits/stdc++.h → non-portable; prefer standard headers.

12. Best practices

  • Pin -std=c++17 (or newer) consistently.
  • Enable -Wall -Wextra.
  • Keep build/ out of source control; add to .gitignore.

13. Troubleshooting

flowchart TD
    A[Compile error] --> B{Compiler on PATH?}
    B -->|No| C[Install / PATH]
    B -->|Yes| D{Header error?}
    D -->|Yes| E[Use g++, -std=c++17]
    D -->|No| F{Link error?}
    F -->|Yes| G[List all objects / -l libs]

14. Production tips

  • CI: Match compiler versions locally and on runners; use reproducible Docker images.
  • Release flags: -O3 -DNDEBUG (with measurements); Debug: -O0 -g.

See also

  • Compiler basics (02-1)
  • VS Code C++ (03)

Keywords

C++ setup, install GCC Clang MSVC, MinGW, Hello World C++, Windows C++ PATH, WSL C++, build-essential.


Closing

Pick one toolchain per project, verify with g++ --version / clang++ --version / cl, then build Hello World. Next: Compiler comparison or #2-1 compiler basics.