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
Decision gist · record as of 2026-06-27
msvc-cl guides you through compiling C/C++ on Windows with cl.exe or clang-cl, covering flag translation, runtime selection, and linker errors. 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.
Use it when
- msvc-cl runtime library selection determines how the C runtime links.
- msvc-cl maps common compiler flags between toolchains: GCC `-O2` → MSVC `/O2`, `-Wall` → `/W4`, `-g` → `/Zi`.
Verify before relying
Read SKILL.md below before installing (2 files). Open directory: indexed for reading, not audited.
Install
mohitmishra786/low-level-dev-skills/msvc-cl · repository language: JavaScript
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently 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)
File tree — 2 files
skills/compilers/msvc-cl/SKILL.md
skills/compilers/msvc-cl/references/flags.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Compile C/C++ code using MSVC cl.exe or clang-cl on Windows”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
Master Clang's superior diagnostics, optimization remarks, and static analysis capabilities. Learn to interpret inlining and vectorization decisions, configure clang-tidy for automated checks, and leverage ThinLTO for faster builds with comparable code quality.
Master GCC flag selection for debug and release builds, from optimization levels and warning discipline to link-time optimization and profile-guided optimization. Covers common compilation errors, sanitizer instrumentation, and integration with GNU Make and CMake.
Dive into compiler internals: understand why loops fail to vectorize, how register pressure causes spills, and when to deploy PGO or BOLT. Covers mid-level IR optimizations, instruction selection, and post-link optimization strategies with practical triage workflows.
Master linker selection, essential flags, and link-order resolution for GNU ld, gold, and lld. Learn to enable LTO with GCC or Clang, strip dead code with --gc-sections, and debug common linker errors like undefined symbols and circular dependencies.
Master modern CMake for C/C++ with target-first principles, out-of-source builds, and dependency management via find_package or FetchContent. Configure generators like Ninja and Make, set up sanitizers, cross-compile with toolchain files, and leverage CMake Presets for reproducible builds.
This skill guides you through building maintainable Makefiles for C/C++ using phony targets, pattern rules, and automatic dependency tracking. Learn to structure multi-file projects, manage compiler flags, diagnose rebuild issues, and convert ad-hoc compile commands into robust build systems.
More skills cloc (MIT)