我正在使用 libgit2,我想将一个包文件写入一个用 git_repository_odb
创建的 odb .所以我调用git_odb_write_pack
并初始化一个 *git_odb_writepack
.然后,当我尝试访问 writepack 结构的字段时,出现编译器错误“取消引用指向不完整类型的指针”。这是代码:
#include <stdio.h>
#include <git2.h>
void check_error(int code, char *action) {
if (code) {
printf("Error %d, %s\n", code, action);
exit(1);
}
}
static int my_git_transfer_progress_callback(const git_transfer_progress *stats, void *payload) {
printf("Got transfer callback\n");
return 0;
}
int main(int argc, char **argv) {
int error;
const char *repo_path = "/path/to/repo";
git_repository *repo = NULL;
error = git_repository_open(&repo, repo_path);
check_error(error, "opening repo");
git_odb *odb = NULL;
error = git_repository_odb(&odb, repo);
check_error(error, "initializing odb");
git_odb_writepack *writepack = NULL;
char *payload = "here's my payload";
error = git_odb_write_pack(&writepack, odb, my_git_transfer_progress_callback, payload);
check_error(error, "opening pack writing stream");
printf("Address: %u\n", writepack->backend); // <-- Line generating the error.
return 0;
}
然后我编译并得到错误:
$ gcc -lgit2 writepack_error.c && LD_LIBRARY_PATH=/usr/local/lib ./a.out writepack_error.c: In function 'main': writepack_error.c:33: error: dereferencing pointer to incomplete type
我正在使用 libgit2 版本 0.21.0。我是 C 和 libgit2 的新手,所以我可能在做一些愚蠢的事情。我的理解是这种“取消引用”错误意味着我未能定义或包含结构或类型定义。但是我认为 libgit2 只需要一个包含,#include <git2.h>
.
最佳答案
git2.h
涵盖了正常用法。某些功能保留在 sys/
目录下,表明它被认为是更高级的用法。
这看起来特别像是一个错误,因为 git2.h
不包含 git2/odb_backend.h
。现在您可以简单地手动包含它。
关于c - 访问 libgit2 中的 git_odb_writepack 字段会出现错误 "dereferencing pointer to incomplete type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25629369/