Build shared libraries without any dynamic dependencies #1688

Open
bnikolic opened this Issue Feb 14, 2014 · 6 comments

Comments

Projects
None yet
4 participants

Currently library targets in Cabal are built with ghc flags "-shared" and "-dynamic". This makes perfect sense when building packages which will be used in further Haskell projects. However when building a library to subsequently be used in a different language environment then it is very convenient to build a library which is dynamically loadable but does not itself have any dynamic dependencies, i.e., all of its dependencies are statically linked. GHC achieves this conveniently with "-shared" "-static" flags.
Currently however there does not seem to be a mixture of options that will make Cabal issue this set of flags to GHC.

Member

23Skidoo commented Feb 15, 2014

So, IIUC, this should be an additional "way" of building libraries - say, shared-deps-static.

I think it should be an option to the existing shared library target. So something like --static-deps and --dynamic-deps with the latter being the default to preserve compatibility.

On 15 Feb 2014, at 00:38, Mikhail Glushenkov notifications@github.com wrote:

So, IIUC, this should be an additional "way" of building libraries - say, shared-deps-static.


Reply to this email directly or view it on GitHub.

bnikolic commented Mar 7, 2014

Just to add: my initial comment is a little Windows specific. On windows the dependent libraries can easily be merged into the resulting single shared library. On Linux I think it would be necessary to compile all the dependent libraries with "-fPIC" even for the static ".a" targets. So making this work would not be entirely painless on Linux.

ttuegel added the enhancement label Apr 23, 2015

ttuegel added this to the _|_ milestone Apr 23, 2015

nokome commented Jun 23, 2016

I need to "build a library which is dynamically loadable but does not itself have any dynamic dependencies" (as per above). Any progress or this or suggestions for workarounds? (I'm a Haskell noob)

I achieved this by having a modified version Cabal. Attached is a patch,
but for ~2014 Cabal version. (Ignore the stdcall alias line)

Bojan Nikolic || http://www.bnikolic.co.uk

nokome commented Jun 23, 2016 edited

Thanks @bnikolic but unfortunately the attached patch didn't come through to here.

Regardless, I think I found a way to do it : cabal install --dependencies-only --ghc-option=-static --ghc-option=-fPIC. That gives me libxxxx.a binaries in ls .cabal-sandbox/lib/x86_64-linux-ghc-7.10.3/xxx. Although I then get errors because the required packages in /opt/ghc/7.10.3/lib/ghc-7.10.3/ were not compiled with -fPIC

Edit. I found this: https://github.com/lyokha/nginx-haskell-module#static-linkage-against-basic-haskell-libraries which appears to provide a solution to this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment