我正在尝试使用 libgit2 的 git_clone()
函数克隆 git 存储库,但是,当我调用该函数时,它返回 -1,并使用 giterr_last()
(如果我使用 git_error_latest()
,我会得到"未定义的引用",不知道为什么(我收到错误"无法创建 ssl 对象"。
我已经查看了相关文件的源代码,在这里,似乎它在第 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()
。将其添加到我的程序的开头解决了这个问题。