msvc-cl
Master Windows C/C++ compilation with MSVC cl.exe and clang-cl. This skill maps GCC/Clang flags to MSVC equivalents, explains runtime library choices (/MT vs /MD), guides PDB setup for debugging, and diagnoses common linker failures. Use it when configuring Visual Studio builds, MSBuild projects, or switching to clang-cl as a drop-in MSVC replacement.
msvc-cl guides you through compiling C/C++ on Windows with cl.exe or clang-cl, covering flag translation, runtime selection, and linker errors.
AI-generated summary based on this skill's SKILL.md
Install
mohitmishra786/low-level-dev-skills/msvc-cl · repository language: JavaScript
git clone https://github.com/mohitmishra786/low-level-dev-skills
cp -r low-level-dev-skills/skills/compilers/msvc-cl ~/.claude/skills/msvc-clnpx skillfed install mohitmishra786/low-level-dev-skills/msvc-clFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How to compile C++ with MSVC cl.exe on Windows?
msvc-cl enables Windows C/C++ compilation via the MSVC cl.exe compiler. Basic syntax: `cl.exe /c source.cpp` compiles to object files, or `cl.exe source.cpp` compiles and links directly. Key flags: `/O2` for optimization, `/W4` for warnings, `/Zi` for debug symbols (PDB), `/MD` for dynamic runtime, `/MT` for static runtime. Set up your environment first with `vcvars64.bat` from your Visual Studio installation to configure paths and toolchain variables.
What is /MT vs /MD in MSVC and when should I use each?
msvc-cl runtime library selection determines how the C runtime links. `/MT` statically links the runtime into your executable (larger binary, no runtime dependency); `/MD` dynamically links it (smaller binary, requires matching MSVC runtime DLL on target). Use `/MT` for standalone tools or when runtime version is uncertain; use `/MD` for libraries in larger projects where runtime is managed centrally. Mismatches cause LNK2038 errors—all object files and libraries in a project must use the same flag.
How do I convert GCC flags to MSVC equivalents?
msvc-cl maps common compiler flags between toolchains: GCC `-O2` → MSVC `/O2`, `-Wall` → `/W4`, `-g` → `/Zi`, `-fPIC` → `/fp:precise` (or omit for Windows), `-std=c++17` → `/std:c++17`. For linking, GCC `-l` becomes MSVC library name directly (e.g., `-lm` → `m.lib`). Use `/D` for defines (GCC `-D`), `/I` for includes (GCC `-I`). The msvc-cl skill guides these translations to help port Unix-centric build scripts to Windows MSVC workflows.
What causes MSVC LNK2038 runtime library mismatch error?
msvc-cl resolves this linker error when object files or libraries use conflicting runtime flags. LNK2038 occurs if one module compiled with `/MD` links against code built with `/MT`, or vice versa. Fix: ensure all source files, libraries, and dependencies use the same `/MD` or `/MT` flag. Check third-party .lib files' documentation for their runtime choice. Rebuild everything with consistent flags, or recompile libraries with matching settings. This skill helps diagnose and prevent such mismatches in complex projects.
Can clang-cl be used as a drop-in replacement for cl.exe?
msvc-cl confirms clang-cl serves as a drop-in MSVC replacement on Windows. clang-cl accepts MSVC command-line syntax (`/O2`, `/MD`, `/Zi`, etc.) and produces compatible object files and PDB debug files. Install clang-cl via LLVM or Visual Studio, then swap `cl.exe` for `clang-cl` in build scripts. Most projects work unchanged; some advanced MSVC-specific features may differ. This skill covers both cl.exe and clang-cl workflows, helping you leverage clang's optimizer or diagnostics while maintaining Windows MSVC compatibility.
How do I generate and use PDB debug files with MSVC?
msvc-cl enables debugging by generating Program Database (PDB) files. Compile with `/Zi` to embed debug info and create a `.pdb` file alongside your executable. Link with `/DEBUG` to ensure the PDB is properly referenced. For optimization, use `/Zo` (enhanced debug info) with `/O2`. Distribute the `.pdb` alongside your `.exe` or `.dll` so debuggers (Visual Studio, WinDbg) can resolve symbols. This skill guides PDB setup for effective post-mortem and live debugging on Windows.
SKILL.md
rendered from the published skill — quoted content, verbatim
MSVC cl.exe and clang-cl
Purpose
Guide agents through Windows C/C++ compilation: MSVC cl.exe, clang-cl as MSVC-compatible driver, MSBuild project settings, and runtime library choices.
Triggers
- "How do I compile with MSVC from the command line?"
- "What is the MSVC equivalent of
-O2?" - "/MT vs /MD — which do I use?"
- "How do I use clang-cl instead of cl.exe?"
- "I'm getting LNK errors on Windows"
- "How do I generate PDB files?"
Workflow
1. Set up the environment
MSVC requires the Visual Studio environment variables. Use the Developer Command Prompt or set up manually:
```cmd REM x64 native "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
REM x86 cross (host x64, target
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 2 files
skills/compilers/msvc-cl/SKILL.md
skills/compilers/msvc-cl/references/flags.md