[Haskell-cafe] Linking to a DLL with relative path on Windows using stack build

Peter Dedecker nectarien at gmail.com
Mon Jul 18 15:06:32 UTC 2016

Hello all,

I am writing a Haskell program that controls a scientific instrument (a very sensitive camera). The instrument vendor makes a Windows DLL available that exposes a C interface. I have already set up the FFI bindings.

I am building the application using Stack on Windows 8. But I am not sure how I can get “stack build” to find the DLL at link time. My Google searches have not cleared things up.

My questions:
1. What global directory should I place the DLL in so “stack build” will pick it up? I tried placing it in C:\Windows\SysWOW64 but that doesn’t work. I realize I could add an "extra-lib-dirs” argument in the .cabal file but I would like to know what the default linker search paths are.

But in fact I prefer to not install the DLL in a hardcoded, global location. Since the instrument is attached to a specific measurement computer, there is no point in having it installed on the developer PCs. I would prefer to have it all self-contained into a single project.
In my C++ development I solve this by placing the DLLs (well, import libraries, really) in a project-specific “lib” directory next to the source code, and under version control.  For example, in Visual Studio my linker path is simply "$(SolutionDir)\..\lib”, which works nicely.

2. But: why can’t I use a project-relative "extra-lib-dirs" argument in the .cabal file? What I would really like is to be able to say "extra-lib-dirs={$projectroot}/lib” in the cabal file. And then, after compilation, I can just copy the binary to the measurement computer (controlling the instrument), copy the DLL into the .exe folder, and have it all work.

Except that it doesn’t work. A relative path in the .cabal file results in "lib is a relative path which makes no sense (as there is nothing for it to be relative to)."
I don’t understand why it makes no sense in this case (where I am linking to a DLL). Seems to me like this does make sense?

Any suggestions on how to go about this? I have stumbled across this: http://stackoverflow.com/questions/24444675/use-relative-paths-for-extra-lib-dirs-on-cabal but that seems awfully hackish and I haven’t been able to get it to work.

With thanks

More information about the Haskell-Cafe mailing list