1

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

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

    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 吗?!

4

3 回答 3

6

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

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.

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.

于 2010-03-10T00:09:59.097 回答
2

64-bit binaries cannot link to 32-bit ones or vice-versa. If you can't get the library you want in 32-bit, your best solution is to create a 32-bit proxy program that your main program controls. This is how Safari does Flash in 10.6 — the Flash plugin runs in its own address space.

于 2010-03-10T00:10:54.850 回答
1

仅供任何偶然发现的人参考,FMOD 的开发版本包含Mac OS X的 64 位 dylib 。我现在正在使用它,我相信它很快就会被移到 API 的主线中。

于 2010-03-10T05:20:57.210 回答