Skip to content

Fix libstdc++-6.dll runtime dependency for Windows mingw-w64 builds#26

Merged
BppleMan merged 3 commits into
mainfrom
copilot/fix-libstdc-dll-issue-again
Oct 27, 2025
Merged

Fix libstdc++-6.dll runtime dependency for Windows mingw-w64 builds#26
BppleMan merged 3 commits into
mainfrom
copilot/fix-libstdc-dll-issue-again

Conversation

Copilot AI commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

Windows executables built with mingwX64 from Linux fail at runtime due to missing libstdc++-6.dll. The Rust core library was dynamically linking to C++ and GCC runtime libraries.

Changes

Rust build configuration (kommand-core/.cargo/config.toml):

  • Add -static-libgcc and -static-libstdc++ rustflags for x86_64-pc-windows-gnu target
  • Statically links GCC and C++ runtime into libkommand_core.a

Kotlin/Native interop (src/nativeInterop/cinterop/x86_64-pc-windows-gnu.def):

  • Replace -static -lstdc++ with -static-libgcc -static-libstdc++
  • Targeted static linking avoids issues with Windows system libraries that lack static variants

Result: Self-contained Windows executables with no external DLL dependencies for standard library runtimes.

Original prompt

This section details on the original issue you should resolve

<issue_title>libstdc++-6.dll Missing on windows</issue_title>
<issue_description>Good evening,
I may be entirely in the realm of wrong as I've only recently started looking into the world of kotlin/multiplatform.
When using IntelliJ on linux and building a mingwx64 binary it will not run on windows when including this library
stating that libstdc++-6.dll is missing or not found. I have tried linker opts below with no luck.

Any ideas outside of installing mingw on windows? Or any idea what would be causing this on all my windows 10/11 instances?
My hopes is a binary without any additional dependencies needed or libs copied alongside the exe

mingwX64() {
    binaries {
        compilerOptions {
            allWarningsAsErrors = true
        }
        executable {
            linkerOpts.addAll(listOf("-static", "-static-libgcc", "-static-libstdc++"))
            entryPoint = "main"
        }
    }
}</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits October 27, 2025 02:06
Configure Rust build to statically link libgcc and libstdc++ for Windows target to eliminate runtime dependency on libstdc++-6.dll. This is achieved through:
1. Adding .cargo/config.toml with rustflags for x86_64-pc-windows-gnu
2. Updating the cinterop .def file with -static-libgcc and -static-libstdc++ linker options

Co-authored-by: BppleMan <16437384+BppleMan@users.noreply.github.com>
…static

Remove the general -static flag and use only -static-libgcc and -static-libstdc++ flags for more targeted static linking. The -static flag can cause issues with Windows system libraries that aren't available in static form.

Co-authored-by: BppleMan <16437384+BppleMan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing libstdc++-6.dll error on Windows builds Fix libstdc++-6.dll runtime dependency for Windows mingw-w64 builds Oct 27, 2025
Copilot AI requested a review from BppleMan October 27, 2025 02:13
@BppleMan BppleMan marked this pull request as ready for review October 27, 2025 02:46
@BppleMan BppleMan requested a review from Copilot October 27, 2025 02:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes runtime dependency issues for Windows executables built with mingw-w64 from Linux by statically linking the GCC and C++ runtime libraries instead of relying on external DLLs.

Key Changes:

  • Added Rust build configuration to statically link GCC and C++ runtimes during Rust compilation
  • Updated Kotlin/Native interop linker options to use targeted static linking flags instead of global -static flag

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
kommand-core/.cargo/config.toml Configures Rust compiler to statically link libgcc and libstdc++ for Windows GNU target
src/nativeInterop/cinterop/x86_64-pc-windows-gnu.def Updates linker flags to use specific static linking options and removes redundant -lstdc++

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

staticLibraries = libkommand_core.a
compilerOpts = -Ikommand-core
linkerOpts = -static -lws2_32 -lbcrypt -luserenv -lntdll -lstdc++ -v
linkerOpts = -static-libgcc -static-libstdc++ -lws2_32 -lbcrypt -luserenv -lntdll -v

Copilot AI Oct 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -v verbose flag should be removed from production linker options as it's a debugging flag that produces unnecessary output during normal builds.

Suggested change
linkerOpts = -static-libgcc -static-libstdc++ -lws2_32 -lbcrypt -luserenv -lntdll -v
linkerOpts = -static-libgcc -static-libstdc++ -lws2_32 -lbcrypt -luserenv -lntdll

Copilot uses AI. Check for mistakes.

@BppleMan BppleMan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purpose

  • Verify that recent Windows linking changes do not break any kommand examples on a Windows runner that does NOT have MinGW installed.
  1. Create the workflow file at .github/workflows/windows-no-mingw-examples.yml with the YAML below and add it to this PR.
  2. Ensure the workflow is committed as part of this PR so it runs against these changes.
  3. Do not install or configure MinGW/MSYS in the workflow—the job must simulate a Windows environment without MinGW.

What the workflow must do

  • Trigger on push and pull_request (restricted to relevant paths).
  • Run on windows-latest.
  • Checkout the repo and set up Java 17 (Temurin).
  • Discover all example subprojects under kommand-examples (folders with build.gradle or build.gradle.kts).
  • For each example: run ./gradlew :kommand-examples:<name>:assemble (fail the job on any non-zero exit).
  • Locate produced native executables (e.g., kommand-examples/**/build/bin/**/*.exe) and run each one (fail the job if any executable exits with non-zero code).
  • Upload per-run logs/artifacts for debugging (stdout/stderr, Gradle logs).

Acceptance criteria

  • CI succeeds only if every example builds and every produced executable exits with code 0.
  • On failure, logs/artifacts are uploaded to aid troubleshooting.

@BppleMan BppleMan assigned Copilot and unassigned Copilot Oct 27, 2025
@BppleMan BppleMan requested review from BppleMan and Copilot October 27, 2025 03:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@BppleMan BppleMan merged commit 43685c4 into main Oct 27, 2025
10 checks passed
@BppleMan BppleMan deleted the copilot/fix-libstdc-dll-issue-again branch October 27, 2025 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libstdc++-6.dll Missing on windows

3 participants