Description
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
- Unzip the example stack project (attached, zip file)
to this directory:
c:\workspace\haskell\bugexample - Build the example (how to build is in the Readme.md file within the above zip)
Expected
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.
Actual
Although I have used those options, ghc is unable to find the foreign library, and hence building of HSDll.dll fails with "missing library"
Workaround
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
library:
* 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 stackage.org or fpcomplete's package repository