我如何使单声道在Linux上接受PE32 DLL
我正在尝试使用MCS
单声道编译器在Linux主机上构建本机Win32应用程序。
我有一个具有以下行的库(coollib.dll
),它
[global::System.Runtime.InteropServices.DllImport("MyLib.dll", EntryPoint="...")]
是使用mcs
进行编译的,因此现在具有以下格式
$ file CoolLib.dll
PE32+ executable (DLL) (console) x86-64 Mono/.Net assembly, for MS Windows
,mylib.dll
也是我的,我用mingw-g ++
在同一主机上编译。
$ file MyLib.dll
MyLib.dll: PE32+ executable (DLL) (console) x86-64, for MS Windows
然后,我编译了我的Hello World可执行文件,即引用coollib.dll
...
mcs /reference:CoolLib.dll /out:main.exe /target:x64 main.cs
MONO_LOG_LEVEL=debug mono main.exe
...但是它用system.dllnotfoundexception
bulbed。
我不明白的是为什么它抱怨mylib.dll
毕竟不是精灵
Mono: DllImport error loading library '/bindings_test/MyLib.dll': '/bindings_test/MyLib.dll: invalid ELF header'.
,但它应该是Win32库。为什么单声道期望它是精灵?
I'm trying to build a native win32 app on Linux host using mcs
mono compiler.
I have a library (CoolLib.dll
) that has the following line
[global::System.Runtime.InteropServices.DllImport("MyLib.dll", EntryPoint="...")]
It's compiled using mcs
and thus has the following format
$ file CoolLib.dll
PE32+ executable (DLL) (console) x86-64 Mono/.Net assembly, for MS Windows
Now, MyLib.dll
is also mine and I compiled on the same host with mingw-g++
.
$ file MyLib.dll
MyLib.dll: PE32+ executable (DLL) (console) x86-64, for MS Windows
I then compile my hello world executable that references CoolLib.dll
...
mcs /reference:CoolLib.dll /out:main.exe /target:x64 main.cs
MONO_LOG_LEVEL=debug mono main.exe
...but it blows up with System.DllNotFoundException
.
Though what I don't understand is why it complains about MyLib.dll
not being an ELF
Mono: DllImport error loading library '/bindings_test/MyLib.dll': '/bindings_test/MyLib.dll: invalid ELF header'.
after all, it's supposed to be a win32 library. Why does mono expect it to be an ELF?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从评论中复制。
您需要记住的一些事实是,
Microsoft决定重复使用托管位的相同文件扩展名和文件格式,因此,像您这样的许多人在移至另一个操作系统之前不会轻易注意到大更改。
因此,要回答您的问题,如果您有一些C/C ++依赖关系可以包装在Linux上,则必须使用本机C/C ++编译器以Elf格式重新编译它们。然后,您的.NET Core/Mono应用程序可以使用PinVoke消耗它们。您不能以PE32格式使用那些本机依赖关系,因为Linux无法识别那是什么。
Copied from the comments.
A few facts you need to keep in mind are,
Microsoft decided to reuse the same file extensions and file format for managed bits, so many people like you won't easily notice the big changes until moving to another operating system.
So to answer your question, if you have some C/C++ dependencies to wrap over on Linux, then they must be recompiled in ELF format using the native C/C++ compiler. Then your .NET Core/Mono apps can use PInvoke to consume them. You cannot use those native dependencies in PE32 format, because Linux won't recognize what's that.
使用
MCS
生成的库是针对目标Intel 80386
,而使用Mingw-g ++
是针对目标x86-64 。
您无法混合平台。为32位或64位窗户构建所有内容。
例如,使用MingW-W64的32位版本使用32位版本,或使用
-M32
标志使用Mingw-W64版本支持这两个目标。The library generated with
mcs
is for targetIntel 80386
while the one built withmingw-g++
is for targetx86-64
.You can't mix platforms. Build everything for either 32-bit or 64-bit Windows.
For example use a 32-bit version by using a 32-bit version of MinGW-w64 or use the
-m32
flag if you have a MinGW-w64 version that supports both targets.