1

I have a .Net Core application which is to run on Ubuntu. With it I'm looking to distribute 2 .so files that the application depends upon. The app would load those libraries via a [DllImport("mylibrary")] attribute.

If I try to run my application as-is, it complains that it cannot find mylibrary. This is because the library doesn't exist in the search path. If I install the libraries via apt-get instead of distributing them, everything works (the libraries end up in /usr/lib/x86_64-linux-gnu/ which is part of my search path for libraries).

This isn't a very scalable solution. I want something that just "works" when running dotnet myapplication.dll without having to pre-install via apt-get (or otherwise) my .so files.

How can I get the library loader to work with my local .so files without requiring some extra step by the end user before running my application?

The idea of having the .Net Core application running some installation / bash commands upon startup to setup the environment sounded like a decent idea except it requires sudo. This isn't a deal-killer, but isn't terribly clean either.

Any ideas?

Ryan Griffith
  • 1,591
  • 17
  • 41
  • Are the libraries you depend on self-contained? In other words: Do they have dependencies they rely on (it's common for one SO to depend on another)? How many Linux distros do you support (things like `libc` can vary between platforms)? How much do you want to blend in with standard Linux practices (people in Linux usually prefer using the package manager to install things, not hacks)? – Travis Gockel Apr 12 '19 at 22:14
  • I don't know how .Net works, but for native binaries you can either have a wrapper script run `LD_LIBRARY_PATH=/mydir/with/libs myprogram` to invoke a program with a specific library search path, or build with `-Wl,-rpath,$ORIGIN` to have it always look for libraries in the same directory as the binary. – that other guy Apr 12 '19 at 22:55
  • @TravisGockel, the two libraries I intend on including are the only dependencies. We will be targeting only 1 distro so we're pretty safe there (Ubuntu 18.04). If we can't get around needing to pre-install the dependencies using apt-get or similar, then it is what it is, but I was just hoping to make something a little more "plug-n-play" (does anyone remember that phase??) than that if possible. – Ryan Griffith Apr 13 '19 at 12:56
  • The harder question is transitive dependencies: You rely on a library that in turn depends on another library. If you're okay with the potential downsides of bundling an SO, this question might have the answer you're looking for: https://stackoverflow.com/questions/8836093/how-can-i-specify-a-dllimport-path-at-runtime/8861895 – Travis Gockel Apr 16 '19 at 00:35

0 Answers0