2

I'm trying to build a simple C++ project (an executable) that calls a Haskell function, using Shake for the build script and calling Stack from within the script to build the Haskell library.

Let's say the Haskell library is called haskell-simple-lib.

The shake script calls stack install haskell-simple-lib which outputs an .so file: libHShaskell-simple-lib-*version*-*unique identifier*.so

My Shake rules depends on filenames, and so I can't use the aforementioned name as I don't know in advance what the unique identifier will be. And so, the Shake script runs a cp on the file to _build/libHShaskell-simple-lib.so

The link options for the C++ executable has -L_build and -lhaskell-simple-lib.

When I try to run the executable I get an error saying:

error while loading shared libraries: libHShaskell-simple-lib-0.1.0.0-8DkaSm3F3d44RUd03fOuDx-ghc7.10.2.so: cannot open shared object file: No such file or directory

But, if I rename the file I copied to _build, to the original name that stack install outputted (the one with the unique identifier), the executable runs correctly.

One would think that all I need to do is to simply cp the file to _build without erasing the unique identifier from the name, however I need to know the name of the .so file in advance for the shake script.

I don't understand why when the executable is run the original .so filename is searched for. The link flag doesn't mention the fullname of the .so that stack install outputted, only libHShaskell-simple-lib. Could it be that the original name is embedded in the .so file? If so, how does one go about solving this issue?

EDIT: I'm aware this could be solved using a dummy file, but I'd like to know if there's a better way to do this.

PsyFish
  • 287
  • 1
  • 9
  • Should you be running `stack install`, or rather `stack build`? You can also pass the `--copy-bins` flag to `stack`, so that it can copy the files by itself without invoking a shake `cp`. – Arnon Dec 05 '16 at 03:37
  • `stack build --copy-bins` is identical to `stack install`. If I use only that instead of `cp` the .so is not renamed, and the shake script fails, as mentioned above. But Thanks! – PsyFish Dec 05 '16 at 09:11

1 Answers1

0

The original identifier is embedded in the .so. I don't remember all the details, but I do know that I've solved such problems using rpath twiddling in the past.

Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85