如何静态链接使用 ./configure 的 Linux 软件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20068947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:23:10  来源:igfitidea点击:

How to static link Linux software that uses ./configure?

linuxgccconfigurestatic-linkingomnios

提问by Sandra Schlichting

I would like to compile NRPEstatic, so I can copy the compiled binary to an OmniOS server, where I don't want gcc to be installed on. I would prefer to install NRPE with SSl support from a repository, but such doesn't seam to exist, so I would like to compile it myself. However the ./configurescript doesn't contain a static option it seams

我想编译NRPE静态,所以我可以将编译后的二进制文件复制到 OmniOS 服务器,我不想在其中安装 gcc。我更喜欢从存储库安装带有 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]

Question

How do I compile a program that uses configurestatically?

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

采纳答案by ams

Try this:

尝试这个:

./configure LDFLAGS="-static"

回答by srd

For people coming from google, I found that if you have libtoolpart of your build, you will need to:

对于来自谷歌的人,我发现如果你有libtool你的构建的一部分,你需要:

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

You can see that -all-staticwith libtool --help --mode=link

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