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:
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?
I'm trying to statically link a package against
zeromq4-haskell
, which is special because it links againstlibzmq
, a C++ library. Based on https://stackoverflow.com/a/37643200 I thought I would only have to add-pgmlg++
to theghc-options
section andstdc++
to theextra-libraries
section: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 myghc-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).