From 51e989e7a5bcb572d20246aca352a14b0ce7fb00 Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Wed, 6 Nov 2024 21:47:30 +0800 Subject: [PATCH] Fix static linking using MinGW-w64 --- src/crystal/system/win32/wmain.cr | 13 ++++++------- src/empty.cr | 4 +++- src/lib_c.cr | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/crystal/system/win32/wmain.cr b/src/crystal/system/win32/wmain.cr index caad6748229f..b3d44370b590 100644 --- a/src/crystal/system/win32/wmain.cr +++ b/src/crystal/system/win32/wmain.cr @@ -2,14 +2,13 @@ require "c/stringapiset" require "c/winnls" require "c/stdlib" -{% begin %} - # we have both `main` and `wmain`, so we must choose an unambiguous entry point +# we have both `main` and `wmain`, so we must choose an unambiguous entry point +{% if flag?(:msvc) %} @[Link({{ flag?(:static) ? "libcmt" : "msvcrt" }})] - {% if flag?(:msvc) %} - @[Link(ldflags: "/ENTRY:wmainCRTStartup")] - {% elsif flag?(:gnu) && !flag?(:interpreted) %} - @[Link(ldflags: "-municode")] - {% end %} + @[Link(ldflags: "/ENTRY:wmainCRTStartup")] +{% elsif flag?(:gnu) && !flag?(:interpreted) %} + @[Link(ldflags: "-mcrtdll=ucrt")] + @[Link(ldflags: "-municode")] {% end %} lib LibCrystalMain end diff --git a/src/empty.cr b/src/empty.cr index 204e30da48c0..118d68ff32c2 100644 --- a/src/empty.cr +++ b/src/empty.cr @@ -1,7 +1,9 @@ require "primitives" -{% if flag?(:win32) %} +{% if flag?(:msvc) %} @[Link({{ flag?(:static) ? "libcmt" : "msvcrt" }})] # For `mainCRTStartup` +{% elsif flag?(:gnu) %} + @[Link(ldflags: "-mcrtdll=ucrt")] {% end %} lib LibCrystalMain @[Raises] diff --git a/src/lib_c.cr b/src/lib_c.cr index 0bd8d2c2cc35..a058670fc4ba 100644 --- a/src/lib_c.cr +++ b/src/lib_c.cr @@ -1,5 +1,5 @@ {% if flag?(:win32) %} - @[Link({{ flag?(:static) ? "libucrt" : "ucrt" }})] + @[Link({{ flag?(:static) && flag?(:msvc) ? "libucrt" : "ucrt" }})] {% end %} lib LibC alias Char = UInt8