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.

4

1 回答 1

0

原始标识符嵌入在.so. 我不记得所有的细节,但我知道我过去曾使用rpathtwiddling 解决过此类问题。

于 2018-06-07T15:35:01.300 回答