Unable to load dynamic library on Linux
- I built a project on Mac OS and the output was a
libmylibrary.so
andlibmylibrary.dylib
files. - I copied the
.dylib
into a Visual Studio Console project and was able to load and invoke the functions of the library using theDllImport
function. The project works as expected - I copied the project (including the
.so
and.dylib
files) into a Ubuntu-based Docker container - When I run the project using
dotnet run
, I get the below error
System.DllNotFoundException: Unable to load shared library 'mylibrary' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libmylibrary, 1): image not found
Edit 1
Below is the Dockerfile used to create the container
FROM streetcred/dotnet-indy AS base
WORKDIR /app
# Expose the default port
EXPOSE 5000
COPY SomeProject/ ./
RUN dotnet restore "SomeProject.csproj"
RUN dotnet build "SomeProject.csproj" -c Release -o build
RUN dotnet publish "SomeProject.csproj" -c Release -o build
RUN COPY libmylibrary.dylib build/libmylibrary.dylib
RUN COPY libmylibrary.so build/libmylibrary.so
CMD dotnet build/SomeProject.dll --urls http://0.0.0.0:5000
Edit 2
I tried the following, but I get the same error
- Compile the
mylibrary
project in a Linux Docker Container (Ubuntu) - Copy the generated
mylibrary.so
file in theSomeProject
Edit 3
Based on @paladin324 comments, I tried the following, but I get the same error
LD_LIBRARY_PATH=/app/SomeProject/build
cd /app/SomeProject/build
dotnet SomeProject.dll --urls http://0.0.0.0:5000