【问题标题】:How to use Libgit2Sharp on Mono/MacOsX?如何在 Mono/MacOsX 上使用 Libgit2Sharp?
【发布时间】:2015-01-17 04:26:34
【问题描述】:

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

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 确实存在。

有没有人见过这个或者知道我可以做些什么来解决它?

更新

我按照@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 . 构建它

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

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 部分。对吗?

【问题讨论】:

    标签: c# mono libgit2sharp


    【解决方案1】:

    LibGit2Sharp 是一个 .Net 绑定到本地 libgit2 库。

    该项目通过使用持续集成服务器(TravisAppVeyor)确保所有测试在 Win 32/64、Linux 和 MacOsX 上运行.

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

    为了实现这一点,您需要 CMake

    您可以从 CI 服务器使用的 build.libgit2sharp.sh script 中获得一些灵感。

    在此 Issue 中,Xamariner(和 LibGit2sharp 核心贡献者)Therzork 分享了有关在 MacOsX 上构建的一些指导。

    更新

    我感觉我搞砸了 cmake 部分。对吗?

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

    确实,每个版本的 LibGit2Sharp 都适用于特定版本的 libgit2。 libgit2 缩写的 commit sha 用于准确表示预期的 libgit2 版本。

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

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

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

    然后运行你的 CMake 魔法。生成的二进制文件现在应该符合 LibGit2Sharp 的预期。

    【讨论】:

    • 那么我需要将 libgit2 二进制文件放在哪里?另外,安装 git 时,libgit2 不是安装的一部分吗?
    • “当你安装 git 时,libgit2 不是安装的一部分吗?” -> 不。不过,这可能很适合另一个问题。
    • “那么我需要将 libgit2 二进制文件放在哪里?” -> 如 Therzork 在最后一个链接中所述,一个简单的方法是:“确保 libgit2本机 livrary 二进制文件与 libgit2sharp DLL 并行,因此您不必弄乱库解析器路径设置。”
    • 感谢您的链接。我已按照说明进行操作,但仍有问题。我用我的结果更新了我的帖子。感谢您的帮助,我来自 Windows C# 世界,所以除了使用 NuGet 之外,我不擅长让 dll 正常工作。
    【解决方案2】:

    libgit2sharp 需要安装 libgit2。你安装了吗?

    https://libgit2.github.com

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-04
      • 1970-01-01
      • 2012-12-15
      • 1970-01-01
      相关资源
      最近更新 更多