sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Self-contained applications in Linux does not work

Open AlbertoMonteiro opened this issue 10 years ago • 27 comments

Steps to reproduce

  • mkdir hwapp
  • cd hwapp
  • dotnet new
  • Modify project.json to match self-contained app
{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.NETCore.App": "1.0.0-rc2-3002702"
  },
  "frameworks": {
    "netcoreapp1.0": {}
  },
  "runtimes": {
    "ubuntu.14.04-x64: {}
  }
}
  • dotnet restore
  • dotnet publish -o out
  • cd out
  • hwapp

Expected behavior

Print Hello World!

Actual behavior

hwapp: command not found

Environment data

.NET Command Line Tools (1.0.0-preview1-002702)

Product Information:
 Version:     1.0.0-preview1-002702
 Commit Sha:  6cde21225e

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  14.04
 OS Platform: Linux
 RID:         ubuntu.14.04-x64

AlbertoMonteiro avatar Jun 06 '16 12:06 AlbertoMonteiro

@AlbertoMonteiro can you share the contents of the out directory?

You should also try running ./hwapp. @brthor suspects this is the issue here.

TheRealPiotrP avatar Jun 06 '16 20:06 TheRealPiotrP

@AlbertoMonteiro I am not able to repro this when using ./hwapp

This is a linux shell requirement, and not something we control in the cli.

Please reopen if you still have issues.

brthor avatar Jun 06 '16 20:06 brthor

I have the same problem, but after exec ./hwapp I get this below error: "Failed to load /home/ubuntu/teste-dotnet-rc2/libcoreclr.so, error: libunwind.so.8: cannot open shared object file: No such file or directory"

henrylle avatar Jun 07 '16 01:06 henrylle

@brthor It worked on the machined(ubuntu.14.04-x64) that I ran the publish command. I copied the output to another Linux distro(AWS Linux), and I got the same error pointed by @henrylle

Failed to load /home/ubuntu/teste-dotnet-rc2/libcoreclr.so, error: libunwind.so.8: cannot open shared object file: No such file or directory

AlbertoMonteiro avatar Jun 07 '16 11:06 AlbertoMonteiro

@henrylle @AlbertoMonteiro Have you installed the dependencies of .NET Core?

You can use the debian package to bring them in with the installation of the cli or you need to install them manually.

You can see the list of packages in this dockerfile: https://github.com/dotnet/cli/blob/rel/1.0.0/scripts/docker/ubuntu.14.04/Dockerfile#L20

brthor avatar Jun 07 '16 16:06 brthor

@AlbertoMonteiro @henrylle The following link helped me resolve the library issue:

http://www.stevenmarkford.com/dotnet-core-failed-to-load-libcoreclr-so-libunwind-so-8-cannot-open-shared-object-file-on-ubuntu/

oshz avatar Sep 08 '16 08:09 oshz

For anyone still running into this, try

apt-get install libunwind8

dejfcz avatar Feb 25 '17 14:02 dejfcz

@dejfcz 's answer solved this problem for me.

Sword-Smith avatar Sep 03 '17 14:09 Sword-Smith

@dejfcz 's answer solved this problem for me too!

josemotta avatar Sep 22 '17 02:09 josemotta

It solves the problem, but not the real issue. The application is not self-contained if it depends on a workaround. A self-contain application should run using just the kernel (i.e. Go with Docker scratch image).

code4clouds avatar Sep 25 '17 23:09 code4clouds

Or at least it should display a message that dependency is not installed

poma avatar Sep 30 '17 07:09 poma

any updates on that? Is it possible to make a build truly self contained and include this dependency somehow?

wklm avatar Nov 04 '17 10:11 wklm

On CoreOS, it's impossible to install libunwind because CoreOS doesn't have a package manager. A workaround is creating a container (Fedora/Ubuntu/etc) and run my .net core app inside it, but it's quite indirect. What's the correct way to deploy self-contained app on CoreOS?

xczdbb avatar Nov 08 '17 02:11 xczdbb

This is not really a CLI issue at this point. When you are running a self-contained app or a portable app, you only use the runtime for that. I would suggest filling a separate issue about native dependencies on CoreOS over at dotnet/core-setup.

livarcocc avatar Nov 08 '17 05:11 livarcocc

could we simply make the libunwind a part of the build in case it's not present on the os?

wklm avatar Nov 08 '17 10:11 wklm

I was having the same problem on ubuntu 17.04, after installing libunwind8 with apt the .NET Core application was running successfully. With a self contained application this should work without the need to install anything

olandese avatar Nov 08 '17 13:11 olandese

Today we published and tried to run simple console app on fresh ubuntu WSL (16.04 LTS) & ubuntu azure (16.04 LTS). dotnetcore2 Tried linux-x64 & ubuntu.16.04-x64 runtime setups.

The same problem appeared. Installing libunwind8 did the job.

Is it going to be fixed at all? This way linux publish is not self contained. PERIOD. We could install full dotnet runtime this way...

ghost avatar Nov 09 '17 13:11 ghost

There is a document describing how to include 3rd party libraries for self-contained apps: https://github.com/dotnet/core/blob/master/Documentation/self-contained-linux-apps.md

Related: https://github.com/dotnet/coreclr/issues/5853 Which was closed with https://github.com/dotnet/coreclr/issues/5853#issuecomment-297864286

After the investigations and various experiments, it turned out that static linking is not feasible from various points of view and that a better approach to achieve portability over Linux distros is to change linking of some dependencies from build time to run time and to enable bundling of local copies of shared libraries. This has proven to work well, so I am closing this issue.

dasMulli avatar Nov 09 '17 14:11 dasMulli

Having the same issue "error: libunwind.so.8: cannot open shared object file: No such file or directory" This needs to be fixed.

WhatFreshHellIsThis avatar Mar 06 '18 19:03 WhatFreshHellIsThis

When all else fails, pull the missing libraries from the microsoft docker image. You can put them in the publish directory and distribute them with your app.

Quick example from my macbook:

Creating the project:

$ mkdir test && cd test
$ dotnet new console && dotnet publish -r linux-x64 --self-contained -o bin

If you run it on linux, expected result:

$ docker run -it -v $(pwd)/bin:/export ubuntu:latest /export/export
Failed to load ��', error: libunwind.so.8: cannot open shared object file: No such file or directory
Failed to bind to CoreCLR at '/export/libcoreclr.so'

Pull the libraries via docker (libunwind and libicu) and to your publish directory:

$ docker run -v $(pwd)/bin:/export microsoft/dotnet:2.0.0-sdk bash -c "cp /usr/lib/x86_64-linux-gnu/libicu* /export/"

$ docker run -v $(pwd)/bin:/export microsoft/dotnet:2.0.0-sdk bash -c "cp /usr/lib/x86_64-linux-gnu/libunwind* /export/"

Re-test:

$ docker run -it -v $(pwd)/bin:/export ubuntu:latest bash -c "LD_LIBRARY_PATH=/export /export/export"
Hello World

Success!

@WhatFreshHellIsThis @dasMulli @FDUdannychen

brthor avatar Mar 07 '18 01:03 brthor