Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用git_clone函数导致SEGFULT_C_Segmentation Fault_Shared Libraries_Libgit2 - Fatal编程技术网

尝试使用git_clone函数导致SEGFULT

尝试使用git_clone函数导致SEGFULT,c,segmentation-fault,shared-libraries,libgit2,C,Segmentation Fault,Shared Libraries,Libgit2,这是我的密码: #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_gi

这是我的密码:

#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;
}
#包括
#包括
内部主(空){
void*libgit2;
int(*球拍复制品)();
git_存储库**out;
const git_clone_options*选项;
libgit2=dlopen(“libgit2.so”,RTLD_-LAZY);
racket_git_clone=dlsym(libgit2,“git_clone”);
(*球拍复制品)(出局,“https://github.com/lehitoskin/racketball“,”/home/maxwell”,选项);
返回0;
}

不知道从哪里开始。有什么想法吗?

从哪里开始是对C语言的回顾,因为您似乎还没有理解指针的用法

您正在传入一个未初始化的指针作为选项,这意味着它指向某个任意内存块,并将导致segfault。选项结构需要是指向堆栈中某个位置的数据结构的指针

您还将传入另一个未初始化的指针作为输出参数,这将导致另一个segfault。指针在那里,所以库可以写入变量,所以您需要告诉它它们在哪里

git_repository *repo;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;

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

看看libgit2 repo中的示例,Ben在上发表了一些关于库用法的博客文章。

从哪里开始是对C语言的概述,因为您似乎还没有理解指针的用法

您正在传入一个未初始化的指针作为选项,这意味着它指向某个任意内存块,并将导致segfault。选项结构需要是指向堆栈中某个位置的数据结构的指针

您还将传入另一个未初始化的指针作为输出参数,这将导致另一个segfault。指针在那里,所以库可以写入变量,所以您需要告诉它它们在哪里

git_repository *repo;
git_clone_options opts = GIT_CLONE_OPTIONS_INIT;

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

看看libgit2 repo中的示例,Ben在上发表了一些关于库使用情况的博客文章。

你确定1)libgit2!=无效的还有那个球拍无效的你对此做过检查吗?你确定1)libgit2!=无效的还有那个球拍无效的你对此做过检查吗?谢谢,我已经好几年没碰过C了,这很尴尬。谢谢,我已经好几年没碰过C了,这很尴尬。