Can't statically link against `zeromq4-haskell` without modifications
- Dominant language
- Nix
- Stars
- 401
- Forks
- 36
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to statically link a package against `zeromq4-haskell`, which is special because it links against `libzmq`, a C++ library. Based on https://stackoverflow.com/a/37643200 I thought I would only have to add `-pgmlg++` to the `ghc-options` section and `stdc++` to the `extra-libraries` section:
```diff
diff --git a/zeromq4-haskell.cabal b/zeromq4-haskell.cabal
index cd4ea53..13e0f82 100644
--- a/zeromq4-haskell.cabal
+++ b/zeromq4-haskell.cabal
@@ -40,7 +40,8 @@ source-repository head
library
hs-source-dirs: src
- ghc-options: -Wall -O2 -fwarn-tabs -funbox-strict-fields
+ ghc-options: -Wall -O2 -fwarn-tabs -funbox-strict-fields -pgmlg++
+ extra-libraries: stdc++
exposed-modules:
Data.Restricted
```
But this did not seem to work. After asking on IRC, I tried adding `-static-libgcc -static-libstdc++` and this didn't work either. Finally @nh2 found that adding `-lstdc++` to the final linker invocation resulted in a working binary, and suggested adding `-optl-Wl,--start-group -optl-lstdc++` to my `ghc-options`. This works, but is not ideal because the consumer of the static library has to know to use this flag instead of the library itself. Is there a better way?
A reproduction is available at https://gist.github.com/vaibhavsagar/219af0ae2ca1e4861806f11de2b62c85 (it uses a slightly different approach for building but the problem and solution are the same).
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.