Reputation: 159
I am using Monodevelop and have a C# main program that calls a Shared Objects file written in C. The solution builds successfully, however when I try to run it, I get the above System.DllNotfoundException and a Fatal Unhandled Exception both pointing to the same Shared Object file.
I have looked at the following:- Calling UNIX and Linux shared object file .so from c# http://mono.1490590.n4.nabble.com/Adding-libraries-to-monodevelop-td1500573.html http://www.mono-project.com/docs/advanced/pinvoke/dllnotfoundexception/ http://www.mono-project.com/docs/advanced/pinvoke/
and set the path to the SO file per here:- https://www.cyberciti.biz/faq/linux-setting-changing-library-path/
The output of ldconfig -v shows the correct folder, but not the .SO file. One of the links suggests that it doesn't matter what the name of the SO file is, however if it is relevant, mine does not begin with 'lib'.
This application has worked previously however due to a company buy out I have taken it over and I am not that familiar with Monodevelop, or indeed C# on a linux platform.
The project builds OK, but will not run as the SO file cannot be found.
I have also included the SO file into the solution in Monodevelop and have set it to be an EmbeddedResource in the Build Action option. Not sure if this is necessary or correct.
The C# code calls:-
[DllImport("xxxxxx.so")]
protected static extern Int32 xxxxxx_init();
and there are some further calls all relating to the same SO file.
Any help gratefully received as always :) J
UPDATE 12th June:- So, I've looked through the log files and have a whole heap of issues. The .SO file could not be located, so I've updated the LDCONFIG to the relevant directory.
That helped, but only in locating the .SO file - it still won't load as the original .SO file was created as 32 bit, and my version of Monodevelop is 64 bit.
Is there a means by which I can compile the c# code in Monodevelop to form a 32 bit executable, or do I have to recompile the shared objects file into a 64 bit version? (from the information I've found looking around the web, my suspicion is the latter, but I'm ever hopeful!)
Upvotes: 2
Views: 2315
Reputation: 1437
Disclaimer: I'm not experienced with Mono (like at all).
You may want to try checking if there are some dependencies in the .so
itself.
From here (I've seen that you mentioned this link, but you didn't say anything about log level or checking dependencies):
Native dependencies and P/Invoke
When using native libraries via P/Invoke you may see similar errors when a library could not be located. Note that when a native library is loaded the native library may attempt to load other libraries on which it depends as well. Any failure seems to result in a DllNotFoundException which only indicates that the original native library being loaded was not found. One may thus end up with a DllNotFoundException while the library is in place.
Troubleshooting this problem can be done setting the debug log level:
$ MONO_LOG_LEVEL=debug mono YourApp.exe <snip> Mono-INFO: DllImport error loading library: 'Interop.so': '/usr/lib/Interop.so: undefined symbol: __some_function <snip>
Upvotes: 1