【问题标题】:How to build git with static linking?如何使用静态链接构建 git?
【发布时间】:2012-07-19 22:22:17
【问题描述】:

我从https://github.com/git/git 下载了 git 源代码作为 zip 文件。

我将它解压缩到 /home/Desktop/denis/git(使用 Ubuntu)。

现在教程here 说我应该运行

./configure --prefix=/home/denis/git-static CFLAGS="${CFLAGS} -static"

从上述文件夹作为构建 git 的一个步骤。

但是 git 源的根文件夹中似乎没有我可以运行的配置文件(只有 configure.ac,我怀疑这不是我要找的)。

我在这里缺少什么?如何手动构建 git?

我这样做是因为我试图让 git 在无法安装 git 的共享托管服务器上工作。

【问题讨论】:

  • make configure 首先。这需要autoconf。

标签: linux git build installation


【解决方案1】:

其他答案对我不起作用。也许他们会为别人。对我有用的是:

  1. 获取源代码
  2. 制作目标目录
  3. 进入源码目录
  4. 配置
  5. 构建
  6. 安装

使用以下命令:

git clone git@github.com:git/git.git
mkdir git-static
cd git
./configure prefix=/path/to/git-static/ CFLAGS="${CFLAGS} -static"
make
make install

这将在git-static 目录中留下一些文件夹,但可执行文件是静态链接的。它也比平时大很多(可能大 1.5 MB)。

【讨论】:

  • 刚刚在最新版本的 Raspbian(针对 OpenWRT 设备)上执行此操作,它警告我仍然会动态加载某些内容。
  • @ThorbjørnRavnAndersen 这可能是因为您使用 glibc 作为您的 C 库,它根本不支持静态链接。最好的选择是使用 musl“交叉编译器”。
  • 这适用于生成静态二进制文件(使用 musl 作为 C 库)。不幸的是,远程后端(如git-remote-https)不包含在 git 二进制文件中。如果有一些选项可以将这些工具包含到主要的 git 二进制文件中,那就太好了。
【解决方案2】:

阅读解压文件根目录下的INSTALL文件,里面似乎有一些有用的指令,我怀疑:

或者,您可以使用 autoconf 生成的 ./configure 脚本来 设置安装路径(通过 config.mak.autogen),所以你可以改写

    $ make configure ;# as yourself
    $ ./configure --prefix=/usr ;# as yourself
    $ make all doc ;# as yourself
    # make install install-doc install-html;# as root

或者简单地说:

    $ make prefix=/usr all doc info ;# as yourself
    # make prefix=/usr install install-doc install-html install-info ;# as root

【讨论】:

  • 我认为这不会构建静态链接的 git。
猜你喜欢
  • 1970-01-01
  • 2022-07-15
  • 1970-01-01
  • 2020-03-22
  • 2013-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多