Giorgi / DuckDB.NET

Bindings and ADO.NET Provider for DuckDB
https://duckdb.net
MIT License
338 stars 61 forks source link

Unable to load shared library 'duckdb' or one of its dependencies #192

Closed petrparik closed 4 weeks ago

petrparik commented 4 weeks ago

Hello! First of all, thanks a lot for this great library! It is very useful.

I use DuckDB.NET inside a PowerShell module written in C#. It works on MS Windows. The same module runs without problems (and without any special touches) also on Ubuntu. Except for stuff that works with DuckDB connections. It fails to open it with the following exception:

System.TypeInitializationException: The type initializer for 'DuckDB.NET.Data.DuckDBConnectionStringBuilder' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'duckdb' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable:
/opt/microsoft/powershell/7/duckdb.so: cannot open shared object file: No such file or directory
/mnt/c/Users/PetrParik/Source/Repos/MyModuleName-artifact/psmodule/MyModuleName/0.0.0.0/duckdb.so: cannot open shared object file: No such file or directory
/opt/microsoft/powershell/7/libduckdb.so: cannot open shared object file: No such file or directory
/mnt/c/Users/PetrParik/Source/Repos/MyModuleName-artifact/psmodule/MyModuleName/0.0.0.0/libduckdb.so: cannot open shared object file: No such file or directory
/opt/microsoft/powershell/7/duckdb: cannot open shared object file: No such file or directory
/mnt/c/Users/PetrParik/Source/Repos/MyModuleName-artifact/psmodule/MyModuleName/0.0.0.0/duckdb: cannot open shared object file: No such file or directory
/opt/microsoft/powershell/7/libduckdb: cannot open shared object file: No such file or directory
/mnt/c/Users/PetrParik/Source/Repos/MyModuleName-artifact/psmodule/MyModuleName/0.0.0.0/libduckdb: cannot open shared object file: No such file or directory

   at DuckDB.NET.Native.NativeMethods.Configure.DuckDBConfigCount()
   at DuckDB.NET.Data.DuckDBConnectionStringBuilder..cctor()
   --- End of inner exception stack trace ---
   at DuckDB.NET.Data.DuckDBConnectionStringBuilder.Parse(String connectionString)
   at DuckDB.NET.Data.DuckDBConnection.get_ParsedConnection()
   at DuckDB.NET.Data.DuckDBConnection.Open()

I'm testing on Ubuntu 22.04.4 LTS inside WSL 2. Any ideas why I'm getting the exception? Thanks a lot!

Giorgi commented 4 weeks ago

It fails because it can't find duckdb.so which is needed to open a connection. I'm not sure how packaging native dependencies works in the case of PowerShell modules. For the NuGet packages, I just put the native files in the runtimes folder and when you reference the package from an app and run it, CLR locates the native library and loads it.

I don't know how to fix it for PowerShell or whether it should be fixed by me or by you.

image

petrparik commented 4 weeks ago

@Giorgi thanks a lot for quick answer! I publish it with "framework-dependent" option, because PS modules do not support self-contained option. I don't have runtimes directory at all. But it works for me with a workaround - I publish with -r linux-x64 --no-self-contained, copy the libduckdb.so to my PS module directory and then all works. Thank you very much for your help!