{"enrichment":{"faq":[{"a":"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.","q":"How to compile C++ with MSVC cl.exe on Windows?"},{"a":"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\u2014all object files and libraries in a project must use the same flag.","q":"What is /MT vs /MD in MSVC and when should I use each?"},{"a":"msvc-cl maps common compiler flags between toolchains: GCC `-O2` \u2192 MSVC `/O2`, `-Wall` \u2192 `/W4`, `-g` \u2192 `/Zi`, `-fPIC` \u2192 `/fp:precise` (or omit for Windows), `-std=c++17` \u2192 `/std:c++17`. For linking, GCC `-l` becomes MSVC library name directly (e.g., `-lm` \u2192 `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.","q":"How do I convert GCC flags to MSVC equivalents?"},{"a":"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.","q":"What causes MSVC LNK2038 runtime library mismatch error?"},{"a":"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.","q":"Can clang-cl be used as a drop-in replacement for cl.exe?"},{"a":"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.","q":"How do I generate and use PDB debug files with MSVC?"}],"shadow_tags":["windows-compiler","msvc-toolchain","link-errors","runtime-libraries","debug-symbols","flag-translation","clang-compatibility","build-configuration"],"summary_rewrite":"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."},"files":[{"bytes":5114,"path":"skills/compilers/msvc-cl/SKILL.md","sha256":"0bd797888c9fdd03d54fae435a1a5f24aede89d7f8b3b911e40a52a7f909e478","url":"https://skillfed.io/files/mohitmishra786/low-level-dev-skills/msvc-cl/726104d2/SKILL.md"}],"id":"mohitmishra786/low-level-dev-skills/msvc-cl","links":{"html":"https://skillfed.io/mohitmishra786/low-level-dev-skills/msvc-cl","md":"https://skillfed.io/mohitmishra786/low-level-dev-skills/msvc-cl.md","repo":"https://github.com/mohitmishra786/low-level-dev-skills"},"meta":{"agents_supported":[],"first_seen":"2026-07-28","forks":19,"language":"JavaScript","last_updated":"2026-06-27","license":"MIT","name":"msvc-cl","publisher":"mohitmishra786","stars":148},"relations":{"similar":[{"id":"mohitmishra786/low-level-dev-skills/clang"},{"id":"mohitmishra786/low-level-dev-skills/pgo"},{"id":"trailofbits/skills/libafl"},{"id":"trailofbits/skills/libfuzzer"},{"id":"mohitmishra786/low-level-dev-skills/linkers-lto"},{"id":"mohitmishra786/low-level-dev-skills/zig-compiler"},{"id":"trailofbits/skills/coverage-analysis"},{"id":"mohitmishra786/low-level-dev-skills/gcc"},{"id":"mohitmishra786/low-level-dev-skills/debug-optimized-builds"},{"id":"mohitmishra786/low-level-dev-skills/cmake"}]},"slug":{"owner":"mohitmishra786","repo":"low-level-dev-skills","skill":"msvc-cl"},"version":"726104d2"}
