A workaround for the “Template Haskell + C” bug?

后端 未结 1 1632
失恋的感觉
失恋的感觉 2021-02-08 17:22

I\'ve got the following situation:

  • Library X is a wrapper over some code in C.
  • Library A depends on library X.
  • Library B uses Template Haskell an
1条回答
  •  囚心锁ツ
    2021-02-08 17:53

    This is really one of the main reasons that 7.8 switched to dynamic GHCi by default. Rather than try to support every feature of every object file format, it builds dynamic libraries and lets the system dynamic loader handle them.

    Try building with the g++ option -fno-weak. From the g++ man page:

    -fno-weak

    Do not use weak symbol support, even if it is provided by the linker. By default, G++ will use weak symbols if they are available. This option exists only for testing, and should not be used by end-users; it will result in inferior code and has no benefits. This option may be removed in a future release of G++.

    There is another issue with __dso_handle. I found that you can at least get the library to load and apparently work by linking in a file which defines that symbol. I don't know whether this hack will cause anything to go wrong.

    So in X.cabal add

    if impl(ghc < 7.8)
        cc-option: -fno-weak
        c-sources: cbits/dso_handle.c
    

    where cbits/dso_handle.c contains

    void *__dso_handle;
    

    0 讨论(0)
提交回复
热议问题