# Status of dynamic linking on Windows

**URL:** <https://discourse.haskell.org/t/status-of-dynamic-linking-on-windows/6917>\
**Category:** Uncategorized\
**Created:** [July 9, 2023, 5:23am UTC](https://discourse.haskell.org/t/status-of-dynamic-linking-on-windows/6917 "2023-07-09T05:23:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradrn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/bradrn/32/264_2.png) [@bradrn](https://discourse.haskell.org/u/bradrn)\
**Post date:** [July 9, 2023, 5:23am UTC](https://discourse.haskell.org/t/status-of-dynamic-linking-on-windows/6917/1 "2023-07-09T05:23:33Z")

</div>

As a motivating example, I have [a program](https://github.com/bradrn/brassica) where the logic is written in Haskell, but the GUI is written in C++ (using Qt). The Haskell code is compiled to a library, which can then be used by the C++ code. On Linux, it’s simple enough to do this by compiling the Haskell package to a shared library with `-dynamic -shared -fPIC -fPIE -flink-rt`. By contrast, on Windows I’ve been compiling it to a static library instead (with `-static -optl-static -staticlib`).

However, in the process of releasing a new version, today I tried recompiling it on Windows, and got a nasty error about `relocation truncated to fit: R_X86_64_32`. Looking this up, apparently it means my static library has gotten too big to link easily — and since GHC doesn’t seem to support changing the code model, the obvious alternative would be to use dynamic linking on Windows too.

Which leads me to my question: what is the status of dynamic linking on Windows currently? The [GHC User’s Guide](https://downloads.haskell.org/ghc/latest/docs/users_guide/win32-dlls.html#building-and-using-win32-dlls) suggests that it should be fairly simple to accomplish. But [the relevant GHC Wiki article](https://gitlab.haskell.org/ghc/ghc/-/wikis/windows-dynamic-linking) says there are problems with the ordinal value getting too large when the DLL has too many symbols. Normally I’d discount a 4-year-old article in favour of the current user’s guide… except that when I tried compiling to a DLL, I did indeed get an error message saying that the ordinals were too large. On Linux, each package is compiled to a separate `.so` file, which keeps them fairly small, but when I try the same GHC options on Windows, it just complains that there are no `'dyn'` versions of the dependencies. Which would seem to indicate that it would work if I could compile the dependencies dynamically, but I can’t find any information on how to do so. This whole situation is quite confusing, and I would greatly appreciate some clarification on GHC’s support for compiling shared libraries on Windows.

---

<div class="post-metadata">

**Author:** ![chreekat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/chreekat/32/2669_2.png) [@chreekat](https://discourse.haskell.org/u/chreekat)\
**Post date:** [July 12, 2023, 10:18am UTC](https://discourse.haskell.org/t/status-of-dynamic-linking-on-windows/6917/2 "2023-07-12T10:18:11Z")

</div>

Hi @bradrn, you might have better luck simply opening an issue on the GHC issue tracker. Or maybe comment on one of the existing ones. Some of them are truly ancient:

- [#4824: Windows: Dynamic linking doesn't work out-of-the-box · Issues · Glasgow Haskell Compiler / GHC · GitLab](https://gitlab.haskell.org/ghc/ghc/-/issues/4824)
- [#5620: Dynamic linking and threading does not work on Windows · Issues · Glasgow Haskell Compiler / GHC · GitLab](https://gitlab.haskell.org/ghc/ghc/-/issues/5620)
- [#8228: GHC built under Windows does not generate dyn\_hi files · Issues · Glasgow Haskell Compiler / GHC · GitLab](https://gitlab.haskell.org/ghc/ghc/-/issues/8228)
- [#16429: Dynamic linking is fragile on Windows · Issues · Glasgow Haskell Compiler / GHC · GitLab](https://gitlab.haskell.org/ghc/ghc/-/issues/16429)

If you don’t have an account already, ping me when you create one so I can manually approve it.

---

<div class="post-metadata">

**Author:** ![bradrn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/bradrn/32/264_2.png) [@bradrn](https://discourse.haskell.org/u/bradrn)\
**Post date:** [July 12, 2023, 11:49am UTC](https://discourse.haskell.org/t/status-of-dynamic-linking-on-windows/6917/3 "2023-07-12T11:49:58Z")

</div>

Thanks for the suggestions @chreekat! But I’m not convinced making another issue will help here… as you note, we already have plenty of issues. I know that the Haskell Foundation maintains a few repos to discuss GHC proposals — perhaps one of those might be more suitable for instigating work in this area?

---

<div class="post-metadata">

**Author:** ![chreekat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/chreekat/32/2669_2.png) [@chreekat](https://discourse.haskell.org/u/chreekat)\
**Post date:** [July 12, 2023, 11:56am UTC](https://discourse.haskell.org/t/status-of-dynamic-linking-on-windows/6917/4 "2023-07-12T11:56:45Z")

</div>

On the one hand, I think that more issues about specific problems are good: you have a really specific reproduction here, and I can’t tell if it’s actually covered by one of the existing issues or not! Specific examples are much better to work with than overly-general ones.

On the other, I don’t know what group, if any, could be a good fit for discussing a problem where everyone agrees it’s a problem but nobody’s working on it. (There’s a lot of those.) Maybe the technical working group? @david-christiansen might have pointers.

---

<div class="post-metadata">

**Author:** ![bradrn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/bradrn/32/264_2.png) [@bradrn](https://discourse.haskell.org/u/bradrn)\
**Post date:** [July 12, 2023, 12:12pm UTC](https://discourse.haskell.org/t/status-of-dynamic-linking-on-windows/6917/5 "2023-07-12T12:12:41Z")

</div>

> [@chreekat](#):
>
> […] you have a really specific reproduction here, and I can’t tell if it’s actually covered by one of the existing issues or not!

Except, sad to say, I don’t really: my ‘specific reproduction’ is just ‘I tried to compile a random program with `-dynamic` and failed on Windows’. It seems likely to me that this is actually caused by the combination of the many smaller dynamic-linking-related issues which GHC has on Windows.

(Ironically, the most specific issue I’m having on Windows is related to _static_ issues: as I said above, it seems straightforwardly the case that the resulting static library is just too large for the code model.)

---

<div class="post-metadata">

**Author:** ![david-christiansen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/david-christiansen/32/2404_2.png) [@david-christiansen](https://discourse.haskell.org/u/david-christiansen)\
**Post date:** [July 12, 2023, 12:17pm UTC](https://discourse.haskell.org/t/status-of-dynamic-linking-on-windows/6917/6 "2023-07-12T12:17:55Z")

</div>

> [@chreekat](#):
>
> Maybe the technical working group?

If you’d like to propose that HF fund getting this fixed, then TWG is the right place to go. Getting to there may require doing a bit of leg-work, however - the first step is to figure out what actually needs to be fixed so that a budget for the work can be drawn up.

I second @chreekat’s recommendation that you create an issue. Even though the program itself is big, if it’s open source, then a decent reproducer would be something like a quick Powershell script that grabs the dependencies and builds it, exhibiting the error.

---

<div class="post-metadata">

**Author:** ![chreekat](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/chreekat/32/2669_2.png) [@chreekat](https://discourse.haskell.org/u/chreekat)\
**Post date:** [July 12, 2023, 12:35pm UTC](https://discourse.haskell.org/t/status-of-dynamic-linking-on-windows/6917/7 "2023-07-12T12:35:08Z")

</div>

(off topic) brassica looks rad, by the way. I’m not a linguist but I do like me some language history.

---

<div class="post-metadata">

**Author:** ![bradrn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/bradrn/32/264_2.png) [@bradrn](https://discourse.haskell.org/u/bradrn)\
**Post date:** [July 12, 2023, 1:44pm UTC](https://discourse.haskell.org/t/status-of-dynamic-linking-on-windows/6917/8 "2023-07-12T13:44:38Z")

</div>

> [@david-christiansen](#):
>
> If you’d like to propose that HF fund getting this fixed […]

Oh, I wasn’t even considering funding! At the moment, all I want is to start a conversation around something which seems like it’s been stalled for many years.

> [@david-christiansen](#):
>
> I second @chreekat’s recommendation that you create an issue. Even though the program itself is big, if it’s open source, then a decent reproducer would be something like a quick Powershell script that grabs the dependencies and builds it, exhibiting the error.

This sounds very reasonable. It doesn’t even need a PowerShell script — it’s basically just `cabal build` then `cmake`. [EDIT: even `cmake` turns out to be unnecessary!] I’ll open an issue now.

> [@chreekat](#):
>
> (off topic) brassica looks rad, by the way. I’m not a linguist but I do like me some language history.

Ooh, thanks! On a GHC-related note: the fancy web interface is thanks to the new WASM backend, which made it considerably easier for me to link up Haskell and JavaScript.

---

<div class="post-metadata">

**Author:** ![bradrn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/bradrn/32/264_2.png) [@bradrn](https://discourse.haskell.org/u/bradrn)\
**Post date:** [July 12, 2023, 2:27pm UTC](https://discourse.haskell.org/t/status-of-dynamic-linking-on-windows/6917/9 "2023-07-12T14:27:24Z")

</div>

Done! See [#23644: Dynamic linking support on Windows · Issues · Glasgow Haskell Compiler / GHC · GitLab](https://gitlab.haskell.org/ghc/ghc/-/issues/23644).
