I added the .so to LDConfig following this article. Still getting the following. You can get the source for the code here. Here is the log from the startup of the binary.
MONO_LOG_LEVEL=debug mono 39dll-4-linux.exe
Mono: gc took 20 usecs
Mono: Assembly Loader probing location: '/usr/lib/mono/4.0/mscorlib.dll'.
Mono: Image addref mscorlib[0x1bd58e0] -> /usr/lib/mono/4.0/mscorlib.dll[0x1bd4c10]: 2
Mono: AOT failed to load AOT module /usr/lib/mono/4.0/mscorlib.dll.so: /usr/lib/mono/4.0/mscorlib.dll.so: cannot open shared object file: No such file or directory
Mono: Assembly Loader loaded assembly from location: '/usr/lib/mono/4.0/mscorlib.dll'.
Mono: Config attempting to parse: '/usr/lib/mono/4.0/mscorlib.dll.config'.
Mono: Config attempting to parse: '/etc/mono/assemblies/mscorlib/mscorlib.config'.
Mono: Assembly mscorlib[0x1bd58e0] added to domain 39dll-4-linux.exe, ref_count=1
Mono: Config attempting to parse: '/etc/mono/config'.
Mono: Config attempting to parse: '/home/nick/.mono/config'.
Mono: Assembly Loader probing location: '39dll-4-linux.exe'.
Mono: Image addref 39dll-4-linux[0x1c520f0] -> /home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/39dll-4-linux.exe[0x1bd3980]: 3
Mono: Assembly 39dll-4-linux[0x1c520f0] added to domain 39dll-4-linux.exe, ref_count=1
Mono: AOT failed to load AOT module /home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/39dll-4-linux.exe.so: /home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/39dll-4-linux.exe.so: cannot open shared object file: No such file or directory
Mono: Assembly Loader loaded assembly from location: '39dll-4-linux.exe'.
Mono: Config attempting to parse: '/home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/39dll-4-linux.exe.config'.
Mono: Config attempting to parse: '/etc/mono/assemblies/39dll-4-linux/39dll-4-linux.config'.
Mono: Assembly Loader probing location: '39dll-4-linux.exe'.
Mono: AOT failed to load AOT module /home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/39dll-4-linux.exe.so: /home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/39dll-4-linux.exe.so: cannot open shared object file: No such file or directory
Mono: Assembly Ref addref 39dll-4-linux[0x1c520f0] -> mscorlib[0x1bd58e0]: 2
Mono: DllImport attempting to load: 'libWinsockLib'.
Mono: DllImport loading library: '/home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/libWinsockLib'.
Mono: DllImport error loading library '/home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/libWinsockLib: cannot open shared object file: No such file or directory'.
Mono: DllImport loading library: '/home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/libWinsockLib.so'.
Mono: DllImport error loading library '/home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/libWinsockLib.so: undefined symbol: __dso_handle'.
Mono: DllImport loading location: 'libWinsockLib'.
Mono: DllImport error loading library: 'libWinsockLib: cannot open shared object file: No such file or directory'.
Mono: DllImport loading location: 'libWinsockLib.so'.
Mono: DllImport error loading library: '/home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/libWinsockLib.so: undefined symbol: __dso_handle'.
Mono: DllImport loading: 'libWinsockLib'.
Mono: DllImport error loading library 'libWinsockLib: cannot open shared object file: No such file or directory'.
Mono: DllImport unable to load library 'libWinsockLib: cannot open shared object file: No such file or directory'.
Mono: DllImport attempting to load: 'libWinsockLib'.
Mono: DllImport loading library: '/home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/libWinsockLib'.
Mono: DllImport error loading library '/home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/libWinsockLib: cannot open shared object file: No such file or directory'.
Mono: DllImport loading library: '/home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/libWinsockLib.so'.
Mono: DllImport error loading library '/home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/libWinsockLib.so: undefined symbol: __dso_handle'.
Mono: DllImport loading location: 'libWinsockLib'.
Mono: DllImport error loading library: 'libWinsockLib: cannot open shared object file: No such file or directory'.
Mono: DllImport loading location: 'libWinsockLib.so'.
Mono: DllImport error loading library: '/home/nick/Projects/39dll-4-linux/39dll-4-linux/bin/Debug/libWinsockLib.so: undefined symbol: __dso_handle'.
Mono: DllImport loading: 'libWinsockLib'.
Mono: DllImport error loading library 'libWinsockLib: cannot open shared object file: No such file or directory'.
Mono: DllImport unable to load library 'libWinsockLib: cannot open shared object file: No such file or directory'.
Unhandled Exception: System.DllNotFoundException: libWinsockLib
at (wrapper managed-to-native) dll4linux.Net:dllInit ()
at dll4linux.SockLib.Init () [0x00000] in <filename unknown>:0
at dll4linux.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: libWinsockLib
at (wrapper managed-to-native) dll4linux.Net:dllInit ()
at dll4linux.SockLib.Init () [0x00000] in <filename unknown>:0
at dll4linux.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
I am completely stumped. Any ideas as to whats going wrong?
FYI, I am invoking the following C# code:
[DllImport("libWinsockLib", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dllInit")]
public static extern Double dllInit();
Finally, I used the following build commands to build the 39dll-4-linux project:
Executed for each .cpp file:
g++ -fPIC -c -o obj/<filename>.o <filename>.cpp
Then I executed:
ld -G obj/*.o -o 39dll4linux.so
Never mind! I figured it out. Turns out, ld is not a good way to package and link a shared library.
Instead of the ld command, i used:
g++ -shared obj/*.o -o 39dll-4-linux.so
It works like a charm!