制作一个 64 位共享库,动态链接到 Mac OS X Snow Leopard 上的 32 位库 [英] Making a 64 bit shared library that dynamically links to a 32 bit library on Mac OS X Snow Leopard

查看:28
本文介绍了制作一个 64 位共享库,动态链接到 Mac OS X Snow Leopard 上的 32 位库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:经过更多阅读,我发现这个问题很普遍,你不能在同一个进程中混合架构,所以 64 位 Java 不能 dlopen() 像 FMOD 这样的 32 位库.是否有任何可能的解决方法,请记住我正在为 FMOD 库编写自己的 C 接口?

Update: After some more reading I see that this problem is totally general, you can't mix architectures in the same process, so 64 bit Java cannot dlopen() a 32 bit library like FMOD. Is there any possible workaround for this, keeping in mind I'm writing my own C interface to the FMOD library?

我需要在 Max OS X 上制作 64 位 dylib,因为 Java Native Access只喜欢 64 位机器上的 64 位库.问题是,我的 C 源代码动态包含 FMOD,它在 Mac 上仅提供 32 位 dylib.当我尝试在没有 -m32 选项的情况下进行编译时(因为我必须输出 64 位 dylib),我收到以下错误:

I need to make a 64-bit dylib on Max OS X because Java Native Access only likes 64-bit libraries on 64-bit machines. The problem is, my C source code dynamically includes FMOD which on Mac only provides 32-bit dylibs. When I try to compile without the -m32 option (since I must output a 64-bit dylib) I get the following error:

    gcc -dynamiclib -std=c99 -pedantic -Wall -O3 -fPIC -pthread -o  ../bin/libpenntotalrecall_fmod.dylib ../../src/libpenntotalrecall_fmod.c -lfmodex -L../../lib/osx/

    ld: warning: in /usr/lib/libfmodex.dylib, missing required architecture x86_64 in file
    Undefined symbols:
      "_FMOD_System_CreateSound", referenced from:
          _startPlayback in ccJnlwrd.o
      "_FMOD_Channel_GetPosition", referenced from:
          _streamPosition in ccJnlwrd.o
      "_FMOD_System_Create", referenced from:
          _startPlayback in ccJnlwrd.o
      "_FMOD_System_PlaySound", referenced from:
          _startPlayback in ccJnlwrd.o
      "_FMOD_Sound_Release", referenced from:
          _stopPlayback in ccJnlwrd.o
      "_FMOD_Channel_IsPlaying", referenced from:
          _playbackInProgress in ccJnlwrd.o
      "_FMOD_System_Update", referenced from:
          _streamPosition in ccJnlwrd.o
          _startPlayback in ccJnlwrd.o
      "_FMOD_Channel_SetPaused", referenced from:
          _startPlayback in ccJnlwrd.o
      "_FMOD_System_Release", referenced from:
          _stopPlayback in ccJnlwrd.o
      "_FMOD_System_Init", referenced from:
          _startPlayback in ccJnlwrd.o
      "_FMOD_Channel_SetVolume", referenced from:
          _startPlayback in ccJnlwrd.o
      "_FMOD_System_Close", referenced from:
          _stopPlayback in ccJnlwrd.o
      "_FMOD_Channel_SetCallback", referenced from:
          _startPlayback in ccJnlwrd.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [all] Error 1

难道不能从我的源代码中得到一个动态包含 32 位库的 64 位 dylib 吗?!

Shouldn't it be possible to get a 64 bit dylib from my source code that dynamically includes 32 bit libraries?!

推荐答案

正如您所指出的,您不能在同一进程中混合架构.

As you've noted, you can't mix architectures in the same process.

解决方法是使用两个进程.其中一个是链接到 32 位库并通过某种 IPC 机制公开其功能的 32 位助手"进程,另一个是链接到您自己的 64 位库的 64 位 Java 进程.

The workaround is then to have two processes. One of them is a 32 bit "helper" process that links to the 32-bit library and exposes its functions through some IPC mechanism, and the other is the 64-bit Java process linked to your own 64-bit library.

您的 64 位库启动辅助进程,并通过 IPC 机制将请求传递给辅助进程并返回结果来提供一组函数.IPC 可以像使用 pipe() 系统调用创建的一对匿名管道一样简单.

Your 64-bit library starts up the helper process, and provides a set of functions that it implements by passing requests to the helper process over the IPC mechanism and returning the results. The IPC can be as simple as a pair of anonymous pipes created with the pipe() system call.

这篇关于制作一个 64 位共享库,动态链接到 Mac OS X Snow Leopard 上的 32 位库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆