Open arvindd opened 6 years ago
I don't have access to a Windows, so I cannot attempt a reproduction. Waiting for someone else to reproduce.
How can I help you here? Do you need some logs from the build of the bugexample.zip 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?
I'm not sure what is needed for a reproduction, but I decided to give it a shot since I have access to a Windows machine and I've encountered similar linking problems (unrelated to this specific issue) while trying to figure out to build Win32 DLLs.
I was able to reproduce the issue by following the instructions in the README.md
file. Here's the non-verbose output of the failed build (including the versions of windows, gcc, and stack):
PS C:\workspace\Haskell\bugexample> systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.18362 N/A Build 18362
PS C:\workspace\Haskell\bugexample> gcc --version
realgcc.exe (Rev1, Built by MSYS2 project) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
PS C:\workspace\Haskell\bugexample> stack --version
Version 2.3.3, Git revision cb44d51bed48b723a5deb08c3348c0b3ccfc437e x86_64 hpack-0.33.0
PS C:\workspace\Haskell\bugexample> stack build
bugexample> configure (lib + exe)
Configuring bugexample-0.0.0...
bugexample> build (lib + exe)
Preprocessing library for bugexample-0.0.0..
Building library for bugexample-0.0.0..
Linking main.exe ...
.stack-work\dist\5c8418a7\build\HLib.o:fake:(.text+0x12a): undefined reference to `printMsg'
collect2.exe: error: ld returned 1 exit status
`gcc.exe' failed in phase `Linker'. (Exit code: 1)
-- While building package bugexample-0.0.0 using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_2.0.1.0_ghc-8.2.2.exe --builddir=.stack-work\dist\5c8418a7 build lib:bugexample exe:bugexample-exe --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
As described in the original post, the build succeeds with the described workaround.
I've also attached the verbose output of the failed build here: build-verbose-output.txt
I have the same problem but in Linux. And ghc-options with -L...
helps too. So, IMHO it's not Windows specific.
bugexample.zip
General summary
This bug surfaces in the following scenario:
Although I have
extra-lib-dirs
in my stack.yaml andextra-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 havingextra-lib-dirs
andextra-libraries
.Steps to reproduce
Expected
When I already have put in
extra-lib-dirs
in my stack.yaml andextra-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:
With this, build succeeds, although I get a warning from stack that says that
extra-lib-dirs
should be used instead of -L andextra-libraries
must be used instead of -l options.Partial output of the build
Stack version
Method of installation
Official binary, downloaded from stackage.org or fpcomplete's package repository