libgit2: git_clone() 失败并出现 "failed to create ssl object" 错误

libgit2: git_clone() fails with a "failed to create ssl object" error

我正在尝试使用 libgit2 的 git_clone() 函数克隆 git 存储库,但是,当我调用该函数时 returns -1,并且使用 giterr_last()(如果我使用 git_error_latest(),我得到 "undefined reference",不知道为什么)我得到错误 "failed to create ssl object"。

我查看了相关文件的源代码,here,似乎它在第 711 行失败了,SSL_new(git__ssl_ctx)

这是我的代码:

#include <string>
#include <git2/clone.h>
#include <git2/errors.h>
#include <git2/common.h>
#include <iostream>

int main() {
    git_repository* pGitRepository = nullptr;
    std::string url = "https://github.com/Newbie13XD/nashmap.git";
    std::string path = "/home/neboula/CLionProjects/gut/foo";
    const git_clone_options* options = nullptr;

    if (git_clone(&pGitRepository, url.c_str(), path.c_str(), options) != 0) {
        const git_error* error = giterr_last();

        std::cout << error->message;
    }

    return 0;
}

我正在使用 g++(版本:Red Hat 8.3.1-2)和 libgit2 版本 0.27.8 进行编译。

我明白了,在使用 libgit2 中的任何其他函数之前,您必须先调用 git_libgit2_init()。将它添加到我的程序的开头解决了这个问题。