使用 GHC (+ LLVM) 将 GMP 静态链接到 Haskell 应用程序 [英] Statically link GMP to an Haskell application using GHC (+ LLVM)
问题描述
我怎样才能放弃对
libgmp
的动态依赖并从这里开始:
How can I drop dynamic dependency on
libgmp
and go from this:
linux-vdso.so.1 => (0x00007fffdccb1000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007fb01afc1000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb01acc7000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb01aabe000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb01a8ba000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb01a69d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb01a2df000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb01b249000)
对此(目前需要):
linux-vdso.so.1 => (0x00007fffdccb1000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb01acc7000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb01aabe000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb01a8ba000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb01a69d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb01a2df000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb01b249000)
以一种干净且可移植的方式,仅适用于所有 GNU/Linux 发行版(并且不会与 BSD(包括 OS X)混淆)?
in a clean and portable way that just works on all GNU/Linux distributions (and not messing up with BSDs (including OS X))?
在分发针对多个 GNU/Linux 发行版的单个 Haskell 二进制文件时,您是否看到任何其他依赖项可能导致上述当前所需列表中的问题?
Do you see any other dependencies that may cause problems in the currently desired list as given above when distributing a single Haskell binary targeting multiple GNU/Linux distributions?
<小时>
注意事项:
- 我的应用程序是 GPLv3,因此不会出现与 GMP 相关的许可证违规问题
- 指定
libgmp.a
的路径不起作用 ( 如何有选择地将某些系统库静态链接到 Haskell 程序二进制文件中? ),libgmp
仍然列在ldd
输出.
- my app is GPLv3 so no license violation issues arise regarding GMP
- Specifying a path to
libgmp.a
does not work ( How to selectively link certain system libraries statically into Haskell program binary? ),libgmp
is still listed in theldd
output.
推荐答案
如果您将 -optl-static -optl-pthread
传递给 GHC,它将静态链接所有运行时库依赖项,包括良好生产规范.在你的 Cabal 文件中设置 ld-options: -static -pthread
应该完成同样的事情.
If you pass -optl-static -optl-pthread
to GHC, it'll statically link all the runtime library dependencies, including GMP. Setting ld-options: -static -pthread
in your Cabal file should accomplish the same thing.
这意味着您也将在 glibc 中进行静态链接,但这可能不会成为问题,尽管它可能会增加二进制文件的大小.使用替代的 libc,如 musl 或 uClibc 应该有助于抵消这种情况,如果这对您来说是个问题.
That means you'll statically link in glibc too, but that probably won't be a problem, although it might increase binary size quite a bit. Using an alternative libc like musl or uClibc should help counteract that, if it's a problem for you.
这篇关于使用 GHC (+ LLVM) 将 GMP 静态链接到 Haskell 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!