0

我在本文之后将 .so 添加到 LDConfig 。仍然得到以下内容。您可以在此处获取代码的源代码。这是二进制文件启动时的日志。

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 

我完全被难住了。关于出了什么问题的任何想法?

仅供参考,我正在调用以下 C# 代码:

[DllImport("libWinsockLib", CallingConvention = CallingConvention.Cdecl, EntryPoint = "dllInit")]
public static extern Double dllInit();

最后,我使用以下构建命令来构建 39dll-4-linux 项目:

为每个 .cpp 文件执行:

g++ -fPIC -c -o obj/<filename>.o <filename>.cpp

然后我执行:

ld -G obj/*.o -o 39dll4linux.so
4

1 回答 1

0

没关系!我想到了。事实证明, ld 不是打包和链接共享库的好方法。

而不是 ld 命令,我使用:

g++ -shared obj/*.o -o 39dll-4-linux.so

它就像一个魅力!

于 2012-07-09T04:21:01.280 回答