【问题标题】:How to static link Linux software that uses ./configure?如何静态链接使用 ./configure 的 Linux 软件?
【发布时间】:2013-11-19 10:25:16
【问题描述】:

我想编译NRPE static,所以我可以将编译后的二进制文件复制到我不想安装 gcc 的 OmniOS 服务器上。我更愿意从存储库安装支持 SSl 的 NRPE,但这种情况并不存在,所以我想自己编译它。但是./configure 脚本不包含它接缝的静态选项

~/nrpe-2.15# ./configure --help | grep static
~/nrpe-2.15# ./configure --help | grep share
  --datadir=DIR          read-only architecture-independent data [PREFIX/share]
  --sharedstatedir=DIR   modifiable architecture-independent data [PREFIX/com]

问题

如何编译静态使用configure 的程序?

【问题讨论】:

标签: linux gcc configure static-linking omnios


【解决方案1】:

试试这个:

./configure LDFLAGS="-static"

【讨论】:

  • 但是我得到了很多warning: Using 'xxx' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
  • 是的,没错,有些东西在运行时会是dlopend。我认为 DNS 查找需要这个,一方面。这并不理想。 :-(
  • 如果您尝试针对 glibc 进行静态链接,则无论如何都无法在 OmniOS 上运行,这需要 illumos libc -- glibc 仅适用于 Linux 内核。
  • 当我运行这个标志时,我得到了configure: error: C++ compiler cannot create executables
  • 我的错误是由缺少包引起的,libstdc++-static 因为有问题的程序使用的是 c++。 This tutorial helped me
【解决方案2】:

对于来自 google 的人,我发现如果您的构建中有 libtool 部分,您将需要:

  1. ./configure CFLAGS="-static" ....
  2. make LDFLAGS="-all-static"

你可以看到-all-staticlibtool --help --mode=link

【讨论】:

  • 这里重要的是,如图所示,LDFLAGS="-all-static"make,而不是在./configure时间设置,否则会破坏配置脚本(因为只有 libtool 包装器接受它,像 gcc 这样的编译器本身不接受)。
  • 又一个讨厌自动工具的理由。 :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-13
  • 1970-01-01
  • 1970-01-01
  • 2019-04-06
  • 2014-03-29
  • 1970-01-01
  • 2021-04-04
相关资源
最近更新 更多