如何在windows上构建git

How to build git on windows?

本文关键字:构建 git windows      更新时间:2023-10-16

我正试图从这个存储库构建Git:Git for windows,据说这是Git的最后一个版本,有特定于windows的更改。我在Windows上的MinGw32环境中工作。

我遇到了以下问题:当我试图构建git时,我得到了:

compat/mingw.h:134:25: fatal error: openssl/ssl.h: 
No such file or directory  #include <openssl/ssl.h>

为什么?我已经在同一环境中使用make->make install序列从源代码构建了一个openssl
特别地,ssl.h被安装到/usr/local/ssl/include/openssl/ssl.h/local/ssl/include/openssl/ssl.h中。

我该如何解决这个问题?

使用MinGW-w64安装MSYS2。

打开Mingw64外壳,添加以下包:

$ pacman -Sy mingw64/mingw-w64-x86_64-openssl 
  mingw64/mingw-w64-x86_64-pcre2 
  mingw64/mingw-w64-x86_64-zlib

克隆并构建Git(如果你还没有Git,你可以下载.zip)

$ git clone https://github.com/git-for-windows/git.git
$ cd git
$ make

截至项目网站的当前答案https://gitforwindows.org/#contribute,是下载";Git for Windows SDK";从那个页面。

当你执行安装程序时,它会克隆SDK,并打开一个";Git for Windows SDK";提示-据我所知,非常接近MINGW64提示。

然后:

sdk cd git
sdk build

你已经设置好了,你有一个本地构建的git.exe!SDK默认安装到C:git-sdk-64,git项目在C:git-sdk-64usrsrcgit中创建。

自2015年以来,您可以通过新的ci(连续集成)文件夹及其ci/run-windows-build.sh脚本(2017年3月)找到更完整的Windows构建示例。

它用于.travis.yml,这意味着您可以将实际构建委托给远程构建环境:travis-ci.org/git/git/builds。
这样,您就不必担心您自己的本地工作站具有或缺少依赖关系。

请先尝试安装openssl,然后尝试构建它。此外,请按照此步骤了解您的问题(尽管它是指定linux的)。

如今,它与Cygwin的配合效果最好。你需要安装它所需要的所有软件包,否则它将导致构建失败。

先决条件:

MSYS2
添加到路径:C:msys64usrbin

pacman -S --needed base-devel mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb mingw-w64-x86_64-curl mingw-w64-x86_64-pcre2

添加到路径:C:msys64mingw64bin


构建:(如果构建用于调试,则忽略此项)

cmd.exe

set MSYSTEM=MINGW64
make

set MSYSTEM=MINGW64和包装mingw-w64-x86_64-curl mingw-w64-x86_64-pcre2对我来说是缺失的


用于调试的构建:https://github.com/git-for-windows/git/wiki/Debugging-Git

创建文件git/config.makgit是从中克隆的repohttps://github.com/git-for-windows/git.git)

DEVELOPER=1
ifndef NDEBUG
CFLAGS := $(filter-out -O2,$(CFLAGS))
ASLR_OPTION := -Wl,--dynamicbase
BASIC_LDFLAGS := $(filter-out $(ASLR_OPTION),$(BASIC_LDFLAGS))
endif

构建

set MSYSTEM=MINGW64
make

使用vscode调试:

{
  "name": "(gdb) C git",
  "type": "cppdbg",
  "request": "launch",
  "program": "${workspaceFolder}\git.exe",
  "args": [
    "rev-parse",
    "HEAD",
  ],
  "stopAtEntry": true,
  "cwd": "${workspaceFolder}",
  "environment": [],
  "externalConsole": false,
  "MIMode": "gdb",
  "setupCommands": [
    {
      "description": "Enable pretty-printing for gdb",
      "text": "-enable-pretty-printing",
      "ignoreFailures": true
    }
  ],
}