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

San*_*ing 18 linux gcc configure static-linking omnios

我想编译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]
Run Code Online (Sandbox Code Playgroud)

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

ams*_*ams 21

试试这个:

./configure LDFLAGS="-static"
Run Code Online (Sandbox Code Playgroud)

  • 我运行此标志时遇到“ configure:error:C ++编译器无法创建可执行文件”的问题。 (2认同)
  • 我的错误是由于缺少软件包libstdc ++-static引起的,因为所讨论的程序正在使用c ++。[本教程对我有帮助](https://www.systutorials.com/5217/how-to-statically-link-c-and-c-programs-on-linux-with-gcc/) (2认同)

srd*_*srd 9

对于来自google的人们,我发现如果您拥有libtool自己的构建的一部分,则需要:

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

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

  • 重要的是,如图所示,将LDFLAGS =“-all-static”`赋予_make_,而未将其设置为`。/ configure`时间,因为否则会破坏配置脚本(仅因为` libtool`包装器接受它,像`gcc`这样的编译器本身不接受)。 (2认同)