如何在Mono/MacOsX上使用Libgit2Sharp? [英] How to use Libgit2Sharp on Mono/MacOsX?

查看:118
本文介绍了如何在Mono/MacOsX上使用Libgit2Sharp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OSX 10.9.5上将Xamarin Studio 5.7和Mono 3.12一起使用.使用NuGet,我下载了libgit2sharp库.我可以在编写代码时使用这些类,没有编译器错误.但是,在运行时出现以下错误:

I am using Xamarin Studio 5.7 with Mono 3.12 on OSX 10.9.5. Using NuGet I downloaded the libgit2sharp library. I am able to use the classes when writing the code, there are no compiler errors. However at run time I get the following error:

Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.DllNotFoundException: git2-91fa31f at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init () at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0 at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0 at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.DllNotFoundException: git2-91fa31f at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init () at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0 at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0 at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0

Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.DllNotFoundException: git2-91fa31f at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init () at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0 at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0 at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.DllNotFoundException: git2-91fa31f at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init () at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0 at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0 at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0

似乎在抱怨它找不到git2-91fa31f dll,但是当我查看程序包文件夹时,我看到该dll确实存在.

It seems to be complaining that it cannot find the git2-91fa31f dll but when I look in the packages folder I can see that that dll does exist.

有没有人以前看过这个,或者知道我能做些什么来解决这个问题?

Has anyone seen this before or know what I can do to fix it?

更新

我遵循@nulltoken的说明并下载了libgit2源.使用cmake -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DBUILD_CLAR:BOOL=OFF -DUSE_SSH=OFF -DENABLE_TRACE=ON -DLIBGIT2_FILENAME=git2-91fa31f -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" ..然后cmake --build .

I followed @nulltoken's instructions and downloaded the libgit2 source. Built it using cmake -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DBUILD_CLAR:BOOL=OFF -DUSE_SSH=OFF -DENABLE_TRACE=ON -DLIBGIT2_FILENAME=git2-91fa31f -DCMAKE_OSX_ARCHITECTURES="i386;x86_64" .. then cmake --build .

这产生了一个名为libgit2-91fa31f.dylib的文件.我将此文件放在项目的exe所在的bin/Debug目录中,而LibGit2Sharp.dll所在的目录中.但是现在当我运行程序时,我得到以下信息:

This produced a file called libgit2-91fa31f.dylib. I placed this file in the bin/Debug directory where the exe of my project is and where LibGit2Sharp.dll is. However now when I run the program I get the following:

Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.EntryPointNotFoundException: git_threads_init at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init () at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0 at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0 at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.EntryPointNotFoundException: git_threads_init at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init () at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0 at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0 at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0

Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.EntryPointNotFoundException: git_threads_init at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init () at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0 at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0 at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0 [ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.EntryPointNotFoundException: git_threads_init at (wrapper managed-to-native) LibGit2Sharp.Core.NativeMethods:git_threads_init () at LibGit2Sharp.Core.NativeMethods+LibraryLifetimeObject..ctor () [0x00000] in <filename unknown>:0 at LibGit2Sharp.Core.NativeMethods..cctor () [0x00000] in <filename unknown>:0 --- End of inner exception stack trace --- at LibGit2Sharp.Core.Proxy.git_repository_open (System.String path) [0x00000] in <filename unknown>:0 at LibGit2Sharp.Repository..ctor (System.String path, LibGit2Sharp.RepositoryOptions options) [0x00000] in <filename unknown>:0

我有种感觉,我弄乱了cmake的部分.正确吗?

I have a feeling I messed up the cmake part. Is that correct?

推荐答案

LibGit2Sharp是与本机libgit2库的.Net绑定.

LibGit2Sharp is a .Net binding to the native libgit2 library.

该项目通过使用持续集成服务器( Travis AppVeyor ).

The project ensures that all the tests run on Win 32/64, Linux and MacOsX through the use of continuous integration servers (Travis and AppVeyor).

但是,当前LibGit2Sharp NuGet软件包仅包含Windows本机编译的二进制文件,因此,将无法在Linux/MacOsX上按原样使用.为了在这些环境中使用LibGit2Sharp,您必须自己构建libgit2.

However, currently the LibGit2Sharp NuGet package only contains the Windows native compiled binaries and, as such, won't be usable as-is on Linux/MacOsX. In order to use LibGit2Sharp in those environments, you'd have to build libgit2 by yourself.

要实现此目的,您需要 CMake .

In order to make this happen, you'll need CMake.

您可以从 build.libgit2sharp中获得启发. CI服务器使用的sh脚本 .

You can get some inspiration from the build.libgit2sharp.sh script that's used by the CI servers.

在此 问题 ,Therzork Xamariner(和LibGit2sharp核心贡献者)共同分享了有关在MacOsX上进行构建的一些指导.

In this Issue, Therzork, a Xamariner (and a LibGit2sharp core contributor), shares some guidance regarding building on MacOsX.

我有种感觉,我弄乱了cmake的部分.正确吗?

I have a feeling I messed up the cmake part. Is that correct?

我认为CMake部分很好.引发的异常是System.EntryPointNotFoundException.这意味着LibGit2Sharp尝试从libgit2调用一个方法,该方法要么不存在,要么其签名(参数,类型,...的数量)与公开的内容不匹配.

I think the got the CMake part is just fine. The exception raised is System.EntryPointNotFoundException. This means that LibGit2Sharp tries to call a method from libgit2 which either doesn't exist or whose signature (number of parameters, types, ...) doesn't match what's exposed.

实际上,每个版本的LibGit2Sharp均可与特定版本的libgit2配合使用. libgit2的缩写commit sha用于精确地确定期望使用哪个版本的libgit2.

Indeed, each version of LibGit2Sharp works against a specific version of libgit2. The libgit2 abbreviated commit sha is used to exactly which version of libgit2 is expected.

版本v0.20.1希望能与提交91fa3af中的libgit2的编译版本一起工作(对于每个LibGit2sharp提交,您可以通过查看libgit2子模块来检查期望的libgit2版本(例如, v0.20.1 )).

Version v0.20.1 expects to work against a compiled version of libgit2 as it was in commit 91fa3af (For each LibGit2sharp commit, you can check the expected libgit2 version by taking a look at the libgit2 submodule (for instance, v0.20.1)).

我的猜测是您实际上正在构建一个不同的libigt2提交(可能是最新的).为了构建commit 91fa31f,请在外壳中运行以下git命令行:

My guess would be that you're actually building a different libigt2 commit (probably the latest one). In order to build commit 91fa31f, run the following git command lines in a shell:

$ git clone https://github.com/libgit2/libgit2
$ cd libgit2
$ git checkout 91fa31f

然后运行您的CMake魔术.现在,生成的二进制文件应符合LibGit2Sharp的期望.

Then run your CMake magic. The produced binary should now match LibGit2Sharp expectations.

这篇关于如何在Mono/MacOsX上使用Libgit2Sharp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆