当我从libgit2中包含git2.h时,我可以访问数据结构,但不能访问函数



这是我基于Ben Straub的(链接博客)的一些代码:

static int do_clone(const char *url, const char *path)
{
    git_repository *repo = NULL;
    int ret = git_clone(&repo, url, path, NULL);
    git_repository_free(repo);
    return ret;
}

下面是我的代码:

#include <git2.h>
int main(void) {
        git_repository *out = NULL;
        git_clone(&out, "https://github.com/lehitoskin/racketball", "/home/maxwell", NULL);
        return 0;
}

我对C非常缺乏经验,所以我很抱歉有这样的基本问题。无论如何,这是我的编译器给我的错误:

maxwell@max-pc ~ $ gcc -I libgit2/include gitfun.c
/tmp/ccB64nPh.o: In function `main':
gitfun.c:(.text+0x31): undefined reference to `git_clone'
collect2: error: ld returned 1 exit status

为什么我不能这样调用git_clone ?

看起来您没有链接到库。如果libgit2是lib名称,则添加-lgit2。

gcc -I libgit2/include gitfun.c -L<path to lib> -l<libname minus the "lib" part>

你编译得很好,但是当链接器去寻找git_clone时,它找不到它,因为你没有指定它所在的库

最新更新