windowshaskellgcclinker-errorsjack

GHC can't find foreign library (libjack.lib) that works with mingw gcc (but not mingw-w64)


Objective:

I am writing a haskell program on Windows 10 using stack and the bindings for jack from hackage. Jack is installed and its lib/include paths are provided to ghc. My objective is to build the program using stack.

Problem:

When I run stack build, I see:

Building all executables for 'hsjack' once  ...
Glasgow Haskell Compiler, Version 8.6.5, stage 2 booted by GHC version 8.6.2
Cabal-simple_Z6RU0evB_2.4.0.1_ghc-8.6.5.exe: Missing dependencies on foreign
libraries:
* Missing (or bad) C libraries: jack64, jack64 ...
While building package hsjack-0.1.0.0 using:
     C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_2.4.0.1_ghc-8.6.5.exe ... 
        --extra-include-dirs=C:\Users\jvall\Tools\jackpackage\includes ...  
        --extra-lib-dirs=C:\Users\jvall\Tools\jackpackage\lib...
    Process exited with code: ExitFailure 1

I've left some uninteresting parts out (indicated by '...'). You can see that the path to the library and include files are included, and I am sure the libraries (libjack.lib, libjack64.lib) and header files are in these directories. I have tried specifying both - jack and - jack64 under extra-libraries: in package.yaml to no difference. Of course, extra-include-dirs and extra-lib-dirs are specified in stack.yaml.

Program versions and other context:

Windows 10

> jackd --version
jackdmp 1.9.11
I installed the JACK2 64-bit binaries available on the jack website.
Contents of C:/.../jackpackage/includes/jack:
jack.h, other *.h files
Contents of C:/../lib:
libjack.def, libjack.lib, libjack64.def, libjack64.lib. (Plus irrelevant libjackserver files. There are no .dlls)

> stack --version
Version 2.3.1, Git revision de2a7b694f07de7e6cf17f8c92338c16286b2878 (8103 commits) x86_64 hpack-0.33.0

> stack exec -- ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.6.5

> stack exec -- gcc --version
realgcc.exe (Rev1, Built by MSYS2 project) 7.2.0

when using mingw
> gcc --version
gcc.exe (MinGW.org GCC Build-20200227-1) 9.2.0

when using mingw-w64
> gcc --version
gcc.exe (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 8.1.0

Possible duplicates:

There are many similar SO posts, but I found none that provided a solution for my case. The vast majority are simply missing the appropriate libraries or programs (1, 2, 3, 4). My problem seems to be caused by an incompatibility between the *.lib files and mingw-w64 and MSYS2 versions of gcc.

Debugging attempts:

To verify that the .lib files work at all, I wrote a simple c program which uses them. The program compiles and runs correctly when using gcc provided by mingw, but it does not run when using the mingw-w64 gcc or stack exec gcc. Sample output using stack exec (heavily abbreviated):

stack exec -- gcc .\test.c -o .\test -I C:\...\includes -L C:\...\lib -ljack64

Target: x86_64-w64-mingw32  
Thread model: posix  
gcc version 7.2.0 (Rev1, Built by MSYS2 project)  
...  
path-to-stack//stack//x86_64-windows//ghc-8.8.3//mingw//bin/../lib/gcc/x86_64-w64-mingw32/7.2.0/collect2.exe  ....  -LC:\\Users\\jvall\\Tools\\jackpackage\\lib ....  
path-to-stack//stack//x86_64-windows//ghc-8.6.5//mingw//bin/ld.exe: cannot find -ljack64  
collect2.exe: error: ld returned 1 exit status

mingw-w64 and stack exec gcc both fail in the same way. Everything looks fine until they can't find the library. Using -m64/-m32 and -ljack/-ljack64 doesn't change anything. I know the Jack2 library is written in C++ and have read that MSVC C++ libraries are incompatible with mingw, but this doesn't explain how mingw successfully compiles when mingw-w64 does not. Is any of this relevant, or should I focus on the haskell/stack side of this problem?

Any ideas what's happening here? How can I use stack to compile a haskell program using the jack bindings? I tried to be thorough, but let me know if I am missing anything. I have minimal examples for both haskell and c programs that reproduce this but the question is already long.


Solution

  • Your binutils is old. The one shipped with GHC 8.6.5 misses this fix https://sourceware.org/bugzilla/show_bug.cgi?id=22948 .Without it -ljack64 won't find libjack64.lib but -llibjack64 would.