commercialhaskell / commercialhaskell/stack

[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

Open
#4,135 4 comments 0 reactions 0 assignees View on GitHub
component: build component: Windows need confirmation needs reproduction type: bug
Dominant language
Haskell
Stars
4.1k
Forks
850
Avg merge
10h 37m
Merged PRs (30d)
4

Description

[bugexample.zip](https://github.com/commercialhaskell/stack/files/2169871/bugexample.zip)
### 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:
c:\workspace\haskell\bugexample
2. 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.