1

Here is some code from Ben Straub's (link blog) that I am basing this on:

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;
}

And here is my code:

#include <git2.h>

int main(void) {
        git_repository *out = NULL;

        git_clone(&out, "https://github.com/lehitoskin/racketball", "/home/maxwell", NULL);

        return 0;
}

I am very inexperienced with C, so I apologize for having such elementary problems. Anyway, here is the error my compiler gives me:

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

Why can't I call git_clone this way?

4

1 回答 1

4

看起来你没有链接到图书馆。如果 libgit2 是库名称,则添加 -lgit2。

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

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

于 2013-06-05T20:13:44.993 回答