且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android的NDK可以包含一个Windows DLL到一个Android共享库?

更新时间:2023-01-19 19:13:13

没有。一个Windows DLL是在不同的格式的Andr​​oid和Linux。

No. A Windows DLL is in a different format to Android and Linux.

Windows使用称为PE COFF格式:可移植可执行,通用对象文件格式。虽然COFF本身来自UNIX,微软有自己的版本。进一步的不兼容性为了支持.NET对象存在。大多数UNIX的和Linux使用ELF - 执行和链接格式。

Windows uses a format known as PE COFF: "Portable Executable, Common Object File Format". Although COFF itself comes from UNIX, Microsoft has its own version. Further incompatibilities exist in order to support .Net objects. Most UNIX's and Linux use ELF - Execute and Link Format.

即使他们是由某种奇迹,用同样的格式,它可能仍然是行不通的,因为机器结构必须是相同的,例如ARM(也有ARM的几种配置)或Intel的x86。

Even if they were, by some miracle, using the same format, it probably still would not work, because the machine architectures would have to be the same, e.g. ARM (and there are several configurations of ARM) or Intel x86.

还有更多。即使你设法让运行DLL,它使用什么呢? DLL文件往往还有其他外部依赖,比如C运行时库,MSVCRT,或 kernel.dll

And there's more. Even if you managed to get the DLL to run, what else does it use? DLLs often have other external dependencies, for example the C runtime library, MSVCRT, or kernel.dll.

所以,就得到了源$ C ​​$ c和本地重新编译它?可能的工作,但Windows的DLL有时有一个可选的的DLLMain()入口点的Linux 的.so 文件没有直接的当量。怎么样code的休息吗?难道是写在一个可移植的方式?它是否坚持使用整个ISO语言标准?要真正的便携,code已经被设计和书面的方式。

So, get the source code and recompile it natively? That might work, but Windows DLLs sometimes have an optional DLLMain() entry point which Linux .so files have no direct equivalent. What about the rest of the code? Is it written in a portable manner? Has it stuck to using the ISO language standard throughout? To be truly portable, code has to be designed and written that way.