[Haskell-cafe] Packaging a library with a separate shared object

Bryan Gardiner bog at khumba.net
Tue Jul 5 06:01:12 UTC 2016


On Mon, 4 Jul 2016 21:39:14 -0400
"Albert Y. C. Lai" <trebla at vex.net> wrote:

> On 2016-06-30 07:03 PM, Bryan Gardiner wrote:
> > I'm working on packaging Qtah (my Qt bindings) for upload to Hackage.
> > This is somewhat complicated, as I have some C++ glue code that I
> > build into a shared library that the Haskell library needs.
> >
> > Currently, my build hooks are as follows, in:
> > https://gitlab.com/khumba/qtah/blob/packaging/qtah/Setup.hs
> >
> > - postConf: Generate Haskell code in src/ and C++ code in cpp/.
> >
> > - preBuild: Add cpp/ to HookedBuildInfo.extraLibDirs because the build
> >    phase needs this needs this.
> >
> > - buildHook: Run make to build the C++ code into libqtah.so before
> >    the Haskell code builds.
> >
> > - copyHook and instHook: Copy libqtah.so into InstallDirs.libdir
> >    (~/.cabal/lib/.../qtah-*/).
> >
> > This installs successfully, but ultimately doesn't work because the
> > Haskell libHSqtah*.so that gets built can't find libqtah.so.  The
> > installation directory ~/cabal/lib/.../qtah-*/ isn't on
> > libHSqtah*.so's RUNPATH (which makes sense, it's not known at link
> > time).  
> 
> I don't know how to write custom Setup.hs, so I don't know how to do the 
> following, but the theory is:
> 
> When creating libHSqtah*.so, the linker needs to be told:
>      -Wl,-rpath,xxx
> Replace xxx by InstallDirs.libdir. This is how to set RUNPATH (or is it 
> RPATH?).

And since installing happens after building, this will in fact require
two packages.  Okay, thanks Albert.

(RUNPATH appears to be the new and preferred way since it doesn't
shadow LD_LIBRARY_PATH, and "-Wl,-rpath=xxx,--enable-new-dtags" looks
like the magic string...)

I went ahead and did the split, and things are working with some small
catches: executables must be linked dynamically because the necessary
RUNPATH isn't set on a statically-linked executable, and I can't seem
to inject the libdir into "cabal test" via HookedBuildInfo the same
way I can with "cabal build".  But overall it works!

Thanks,
Bryan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160704/33d67a38/attachment.sig>


More information about the Haskell-Cafe mailing list