Skip to content

Cannot find native library. #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
phrohdoh opened this issue Jul 23, 2014 · 20 comments
Closed

Cannot find native library. #786

phrohdoh opened this issue Jul 23, 2014 · 20 comments

Comments

@phrohdoh
Copy link

No matter where I put the native library libgit2sharp refuses to fine it.
The tiny project can be found here.

using System;
using System.IO;
using System.Linq;
using LibGit2Sharp;

namespace GitSharp
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("\targ1: output dir\n\targ2: repo http url");
                return;
            }

            var outputDir = Path.Combine(Environment.CurrentDirectory, args[0]);

            if (!Directory.Exists(outputDir))
                Directory.CreateDirectory(outputDir);

            Console.WriteLine("Output: {0}", outputDir);

            var repoSource = args[1];
            Console.WriteLine("Repo: {0}", repoSource);

            var native = File.Exists("git2-90befde.dll");
            Console.WriteLine("Native exist: {0}", native);

            var path = Repository.Clone(repoSource, outputDir);

            using (var repo = new Repository(path))
            {
                Console.WriteLine("Branches {0}.", repo.Branches.Count());
            }
        }
    }
}

$ mono --debug GitSharp.exe out https://github.com/Phrohdoh/libdrs
crashes with

Unhandled Exception:
System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.DllNotFoundException: git2-90befde
  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_clone (System.String url, System.String workdir, LibGit2Sharp.Core.GitCloneOptions& opts) [0x00000] in <filename unknown>:0 
  at LibGit2Sharp.Repository.Clone (System.String sourceUrl, System.String workdirPath, LibGit2Sharp.CloneOptions options) [0x00000] in <filename unknown>:0 
  at GitSharp.MainClass.Main (System.String[] args) [0x00067] in /Users/thill/Projects/GitSharpTest/GitSharp/GitSharp/Program.cs:31 
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: An exception was thrown by the type initializer for LibGit2Sharp.Core.NativeMethods ---> System.DllNotFoundException: git2-90befde
  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_clone (System.String url, System.String workdir, LibGit2Sharp.Core.GitCloneOptions& opts) [0x00000] in <filename unknown>:0 
  at LibGit2Sharp.Repository.Clone (System.String sourceUrl, System.String workdirPath, LibGit2Sharp.CloneOptions options) [0x00000] in <filename unknown>:0 
  at GitSharp.MainClass.Main (System.String[] args) [0x00067] in /Users/thill/Projects/GitSharpTest/GitSharp/GitSharp/Program.cs:31
iMac:Debug thill$ ls
./                ../               GitSharp.exe*     GitSharp.exe.mdb  LibGit2Sharp.dll  git2-90befde.dll  out/

I've included binaries in that repo in hopes of resolving this easier.
Sorry if this is too long / unhelpful issue.

@nulltoken
Copy link
Member

The binaries included in the NuGet package are Windows only ones.

In order to make this work on Linux/MacOSX, you'll have to build libgit2 by yourself and include the path to the compiled binary in [DY]LD_LIBRARY_PATH.

See the build.libgit2sharp.sh script that's being used by Travis to build and run tests on Linux/MacOSX for more gory details.

@DavidKarlas
Copy link

Maybe this will be helpful... https://github.com/mono/libgit-binary which is used here: https://github.com/mono/monodevelop/tree/libgit2ftw to make quick test

@phrohdoh
Copy link
Author

I was able to build libgit2 then when attempting to build libgit2sharp I am given:
http://pastebin.com/AjVYdi8n.

Is there a directory I need to create before compilation?

@DavidKarlas, thanks I'll look into that!
My only problem is needing this to run the same across OS X/Linux/Windows, but that may be a good temporary fix.

Edit:

So I found out that the invalid path expands (via some csproj magic) to:
"$(MSBuildProjectDirectory)\..\Lib\NativeBinaries\**\*.*"
which is in fact a real/existing directory.
Because of this I have no idea what is preventing the dylib/so from being built successfully.

@nulltoken
Copy link
Member

Is there a directory I need to create before compilation?

@phrohdoh Every required directory should be automatically created.

"$(MSBuildProjectDirectory)\..\Lib\NativeBinaries\**\*.*" is the directory that contains the Win32 builds. The build recipe expects it to exists and will copy the dependencies although they're not required on Linux/Mac.

The error seems to occur while copying those native dependencies (/Users/thill/Projects/libgit2sharp/LibGit2Sharp/CopyNativeDependencies.targets: error : Error executing task CreateItem: Invalid path).

  • Could you please tweak the call to xbuild to make it run in verbose mode?
  • What's the output when performing a fresh clone, then launching build.libgit2sharp.sh ?

@phrohdoh
Copy link
Author

Sorry for the late response, and thank you for the help so far.

A fresh clone would not have libgit2 to work with. This is a fresh libgit2sharp with a built libgit2.
I set /verbosity:diagnostic hoping to get the most amount of debug info:
http://pastebin.com/1rhM0JKG.

@nulltoken
Copy link
Member

A fresh clone would not have libgit2 to work with. This is a fresh libgit2sharp with a built libgit2.

Actually the full request was "What's the output when performing a fresh clone, then launching build.libgit2sharp.sh?". The last step takes care of building libgit2.

Could you perform the whole task (fresh clone + launch the shell script) and share with us the result?

@phrohdoh
Copy link
Author

Oh, right, sorry about that misunderstanding!
Here is the result of that: http://pastebin.com/X5bYz3nJ

@nulltoken
Copy link
Member

Here is the result of that: http://pastebin.com/X5bYz3nJ

Thanks for that. In the log we can see "/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/Microsoft.Common.targets"

@Therzok pointed this out in #733.

Two options :

  • Either downgrade or upgrade. It passes against both Mono 2.10 and 3.6.
  • Help use and it work under 3.4. If you feel like diving into MSBuild and can find a way to make CopyNativeDependencies under Mono 3.4, we'd very interested. 😉

@phrohdoh
Copy link
Author

TL;DR this output, git2-091165c.dll cannot be found (but it does exist).
This is from a fresh clone and a ./build.libgit2sharp.sh after upgrading to Mono 3.6.1
on OS X 10.9.3, not sure why it is still requesting these win32 dlls.

@Just1n
Copy link

Just1n commented Aug 13, 2014

I'm meeting the same prob System.DllNotFoundException : git2-091165c when run build.libgit2sharp.sh in Ubuntu.

@Therzok
Copy link
Member

Therzok commented Aug 13, 2014

@phrohdoh it's not looking for the .dll, but the actual compiled library through the shell script.

@phrohdoh
Copy link
Author

Still no resolution after fresh cloning and updating libgit2sharp + mono.
Closing.

@nulltoken
Copy link
Member

@Therzok Does it make any sense to you that @phrohdoh wasn't able to make it work? Have we missed something obvious?

@nulltoken
Copy link
Member

/cc @carlosmn

@Therzok
Copy link
Member

Therzok commented Sep 19, 2014

The DYLD_LIBRARY_PATH isn't set for finding the native binaries. That means it will never resolve them. It doesn't matter if they're in the same directory or in a different directory. DYLD_LIBRARY_PATH must specify the location of the native libraries.

Also, it's not requesting the .dlls. It's requesting libraries which it can map.

@phrohdoh
Copy link
Author

Building libgit2sharp does not result in anything other than new .dlls; there is nothing to map.
Also setting DYLD_LIBRARY_PATH for my system will not help on the client end.

Is there an obvious step I am overthinking?

@Therzok
Copy link
Member

Therzok commented Sep 19, 2014

Building libgit2sharp does result in files /libgit2/build.

@phrohdoh
Copy link
Author

Wow, thank you so much! I don't know how I never saw those dylibs.

It is partially working now, though I am getting some conflicting reports; in general libgit2sharp is working now.

Sorry for the trouble and again thank you for the help!

@Therzok
Copy link
Member

Therzok commented Sep 19, 2014

It's not your fault. It's all hidden in the testing script for LibGit2Sharp. We need to make the Unix experience slightly more delightful.

@nulltoken
Copy link
Member

Agreed. Logged in #837

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants