c - 访问 libgit2 中的 git_odb_writepack 字段会出现错误 "dereferencing pointer to incomplete type"

标签 c libgit2

我正在使用 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/

相关文章:

string - GCC 编译器的问题

c++ - 使用我自己的源目录生成 vs2010 项目文件

java - 为什么 Java 在这里运行得比 C 快?

git - 尝试使用 git2-rs/libgit2 推送到远程时出现 "request failed with status code: 401"错误

libgit2(获取、合并和提交)

linux - libgit2 alpine linux docker 错误

c - 链表指针问题

c - 为什么使用线程时程序的输出总是不同?

python - 使用 pygit2 提交时未跟踪的目录

git - libgit2 返回 : Refspec 'refs/heads/origin/HEAD' not found error in TortoiseGit