[Mono-list] dlopen problem on Mono 2.4.4
jonpryor at vt.edu
Thu Jan 27 12:45:15 EST 2011
No idea about the SIGSEGV, but your code could use some improvement...
On Jan 27, 2011, at 1:43 AM, batuakan wrote:
> c# source code
> using System;
> using System.ComponentModel;
> using System.Runtime.InteropServices;
> namespace swi
> class MainClass
> [DllImport("libdl.so", CallingConvention = CallingConvention.Cdecl,
> CharSet = CharSet.Auto)]
First of all, "libdl.so" may not exist; it certainly doesn't exist on my openSUSE 11.2 installation, as it's part of a debug package which I don't have installed. You either want to [DllImport ("libdl.so.2")] or provide a .exe.config file which maps libdl.so to the actual library:
> private static extern IntPtr dlopen([In] string filename, [In] int flags);
[In] isn't necessary (as it's the default), but it won't hurt anything either.
> public static void Main (string args)
> IntPtr handle = dlopen("libc.so.6", 0x02);
> if (handle == null)
This is wrong; it will ~never be true, as in order to operate you would need to box the IntPtr into an object to compare against null, and a boxed object will obviously never be null.
(Plus, iirc many mcs versions will error on the above code because the C# spec was interpreted to prevent that, as it's obviously non-sensical.)
Instead, you should do:
if (handle == IntPtr.Zero)
More information about the Mono-list