简体   繁体   English

将 32 位库链接到 64 位程序

[英]Linking 32-bit library to 64-bit program

I have a 32-bit .so binary-only library and I have to generate 64-bit program that uses it.我有一个 32 位的 .so 二进制库,我必须生成使用它的 64 位程序。 Is there a way to wrap or convert it, so it can be used with 64-bit program?有没有办法包装或转换它,以便它可以与64位程序一起使用?

No. You can't directly link to 32bit code inside of a 64bit program.不可以。您不能直接链接到 64 位程序中的 32 位代码。

The best option is to compile a 32bit (standalone) program that can run on your 64bit platform (using ia32) , and then use a form of inter-process communication to communicate to it from your 64bit program.最好的选择是编译一个可以在您的 64 位平台上运行的 32 位(独立)程序(使用 ia32) ,然后使用一种进程间通信的形式从您的 64 位程序与它进行通信。

有关使用 IPC 从 64 位代码运行 32 位插件的示例,请查看开源NSPluginWrapper

It is possible, but not without some serious magic behind the scenes and you will not like the answer.这是可能的,但并非没有幕后一些严肃的魔法,你不会喜欢这个答案。 Either emulate a 32 bit CPU (no I am not kidding) or switch the main process back to 32 bit.要么模拟 32 位 CPU(不,我不是在开玩笑)要么将主进程切换回 32 位。 Emulating may be slow though.不过,模拟可能会很慢。

This is a proof of concept of the technique.这是该技术概念证明

Then keep a table of every memory access to and from the 32 bit library and keep them in sync.然后保存一个表,记录每个内存访问和来自 32 位库的内容,并使它们保持同步。 It is very hard to get to a theoretical completeness, but something workable should be pretty easy, but very tedious.达到理论上的完整性是非常困难的,但可行的事情应该很容易,但很乏味。

In most cases, I believe two processes and then IPC between the two may actually be easiest, as suggested othwerwise.在大多数情况下,我相信两个进程,然后在两者之间进行 IPC 实际上可能是最简单的,正如 otherwise 所建议的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM