0

Here is my code:

#include <git2.h>
#include <dlfcn.h>

int main(void) {
    void *libgit2;
    int (*racket_git_clone)();
    git_repository **out;
    const git_clone_options *options;

    libgit2 = dlopen("libgit2.so", RTLD_LAZY);
    racket_git_clone = dlsym(libgit2, "git_clone");
    (*racket_git_clone)(out, "https://github.com/lehitoskin/racketball", "/home/maxwell", options);

    return 0;
}

No clue where to start. Any ideas?

Alex V
  • 3,416
  • 2
  • 33
  • 52

1 Answers1

3

Where to start is a recap of the C language, as it looks like you haven't yet understood the usage of pointers.

You're passing in an uninitialized pointer as the options, which means it's pointing to some arbitrary piece of memory, and will cause a segfault. The options structure needs to be a pointer to the data structure you have in your stack somewhere.

You're also passing in another uninitialized pointer as the output parameter, which is going to cause yet another segfault. The pointers are there so the library can write to your variables, so you need to tell it where they are.

git_repository *repo;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;

git_clone(&repo, "source", "dest", &opts);

Take a look at the examples in the libgit2 repo and Ben has a few blog posts about the library usage at http://ben.straub.cc/.

Ben Straub
  • 5,675
  • 3
  • 28
  • 43
Carlos Martín Nieto
  • 5,207
  • 1
  • 15
  • 16