C
C#3y ago
nekodjin

DllImport Troubles

Hello there. I'm running on linux. I'm trying to load symbols from a library named libxyz.so. I have written it as such:
[DllImport("xyz", EntryPoint = "blahblahblah")]
[DllImport("xyz", EntryPoint = "blahblahblah")]
however, I get this runtime error:
Unhandled Exception. System.DllNotFoundException: Unable to load shared library './xyz' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: ./xyz: cannot open shared object file: No such file or directory
Unhandled Exception. System.DllNotFoundException: Unable to load shared library './xyz' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: ./xyz: cannot open shared object file: No such file or directory
I used the LD_DEBUG environment variable as instructed, and discovered that while the runtime is correctly identifying the possible permutations (xyz, libxyz, xyz.so, libxyz.so) it is only searching for those permutations in the system search path (i.e. /usr/lib) and nowhere else. That is to say, it is not searching the current directory, which is where the file is located. How can I remedy this?
15 Replies
nekodjin
nekodjinOP3y ago
please ping on response
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
nekodjin
nekodjinOP3y ago
i don't use IDEs
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
nekodjin
nekodjinOP3y ago
i'll look up the relevant fields of *.csproj
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
nekodjin
nekodjinOP3y ago
hmm. i don't see any relevant msbuild properties wait MS documentation be good challenge
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
reflectronic
reflectronic3y ago
there are no relevant MSBuild properties that change this behavior
nekodjin
nekodjinOP3y ago
hmm. i still can't get it working this didn't solve it how should i resolve it?
reflectronic
reflectronic3y ago
well, i don't know why it isn't working--i don't know too many specifics about the dynamic linker on linux. the behavior is pretty standard. if you try NativeLibrary.Load("libxyz.so") and it still doesn't work, that is directly equivalent to dlopen("libxyz.so", RTLD_LAZY). so whatever fixes that would fix this
reflectronic
reflectronic3y ago
this might be a somewhat naive thing to say but i am pretty sure dlopen doesn't search the current directory by default https://linux.die.net/man/3/dlopen
dlopen(3) - Linux man page
dlopen() The function dlopen() loads the dynamic library file named by the null-terminated string filename and returns an opaque "handle" for the dynamic library.
nekodjin
nekodjinOP3y ago
hmm ok i got it to work the path needs to contain a / to be treated as a path otherwise it looks for it in the system libraries
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
nekodjin
nekodjinOP3y ago
unfortunately this means it's not cross-platform. so #if and friends need to be used but that's ok figured it out methinks
Want results from more Discord servers?
Add your server