Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] extra-libraries and extra-lib-dirs are not passed to the linker / ghc for linking when building a haskell DLL that depends on another foreign DLL #4135

arvindd opened this issue Jul 6, 2018 · 2 comments


Copy link

@arvindd arvindd commented Jul 6, 2018

General summary

This bug surfaces in the following scenario:

  • I am on a Windows system (so we are talking of DLLs as "shared library" below
  • I am building a Haskell library as a shared library (DLL) - HSDll.dll
  • And this shared library depends on another foreign DLL

Although I have extra-lib-dirs in my stack.yaml and extra-libraries package.yaml, I see these do not get passed on to the linker while building the Haskell DLL.

I had to specifically add -L (for searching library directories) and -l (for linking a specific .lib file) in my ghc-options (apart from also having extra-lib-dirs and extra-libraries.

Steps to reproduce

  1. Unzip the example stack project (attached, zip file)
    to this directory:
  2. Build the example (how to build is in the file within the above zip)


When I already have put in extra-lib-dirs in my stack.yaml and extra-libraries package.yaml, it should be possible that HSDll.dll is getting built without any problems.


Although I have used those options, ghc is unable to find the foreign library, and hence building of HSDll.dll fails with "missing library"


As a workaround, I put these lines as additional lines in the ghc-options in package.yaml:

     - -lclib
     - -LC:\\workspace\\Haskell\\bugexample\\src\\clib

With this, build succeeds, although I get a warning from stack that says that extra-lib-dirs should be used instead of -L and extra-libraries must be used instead of -l options.

Partial output of the build

PS C:\workspace\Haskell\bugexample> stack build
Building all executables for `bugexample' once. After a successful build of all of them, only specified executables will be rebuilt.
bugexample-0.0.0: configure (lib + exe)
Configuring bugexample-0.0.0...
Cabal-simple_Z6RU0evB_2.0.1.0_ghc-8.2.2.exe: Missing dependency on a foreign
* Missing C library: clib
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.

Stack version

S C:\workspace\Haskell\bugexample> stack --version
Version 1.7.1, Git revision 681c800873816c022739ca7ed14755e85a579565 (5807 commits) x86_64 hpack-0.28.2

Method of installation

Official binary, downloaded from or fpcomplete's package repository


This comment has been minimized.

Copy link

@mihaimaruseac mihaimaruseac commented Jul 6, 2018

I don't have access to a Windows, so I cannot attempt a reproduction. Waiting for someone else to reproduce.


This comment has been minimized.

Copy link

@arvindd arvindd commented Jul 9, 2018

How can I help you here? Do you need some logs from the build of the that I've attached? Is there some specific thing that I can do before running the build (eg: env variables, etc.) so that you get more information for debugging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.