13

libjvm(JNI バインディングを行うために必要な JDK のライブラリ)とのリンケージを必要とするアプリケーションがあります。libjvm.dylib使用する場所を指定する-Lと、正常にコンパイルおよびリンクされます。ただし、バイナリを実行すると、次のようになります。

dyld: Library not loaded: @rpath/libjvm.dylib
  Referenced from: <my home directory>/./mybinary
  Reason: image not found

これまでのところ、次のように LD_LIBRARY_PATH を指定してバイナリを実行できることがわかりました。

LD_LIBRARY_PATH=<path to libfolder installation> ./mybinary

しかしもちろん、私はそれを望んでいません。アプリケーションを起動するたびに正確な場所を何度も指定しなければならないのに、なぜ正確な場所を指定する必要があるのでしょうか?!

また、Mac OS X の動的ライブラリは、場所を示す一種のスタンプを取得することも知りました。ただし、何が何であるかはわかりませんrpath(私には変数のように見えますが、リンク中にどのように設定できますか?)。

このアプリケーションは Haskell を使用して構築されていますが、オブジェクト ファイルを手動でリンクすることもできますld。しかし、私はそのrpathにこだわっています.JDKライブラリにとって特別なのでしょうか?

ビルドするために私が行うことは次のとおりです。

ghc --make Main.hs mycbinding.o -ljvm -L<javahome>/jre/lib/server -o mybinary
4

1 に答える 1

14

Appleのdyldmanページから:

@ rpath /

  Dyld maintains a current stack of paths called the run path list.
  When @rpath is encountered it is substituted with each path in the
  run path list until a loadable dylib if found. The run path stack
  is built from the LC_RPATH load commands in the depencency chain
  that lead to the current dylib load. You can add an LC_RPATH load
  command to an image with the -rpath option to ld(1). You can even add
  a LC_RPATH load command path that starts with @loader_path/, and it
  will push a path on the run path stack that relative to the image
  containing the LC_RPATH. The use of @rpath is most useful when you
  have a complex directory structure of programs and dylibs which can be
  installed anywhere, but keep their relative positions. This scenario
  could be implemented using @loader_path, but every client of a dylib
  could need a different load path because its relative position in the
  file system is different. The use of @rpath introduces a level of
  indirection that simplies things. You pick a location in your directory
  structure as an anchor point. Each dylib then gets an install path that
  starts with @rpath and is the path to the dylib relative to the anchor
  point. Each main executable is linked with -rpath @loader_path/zzz,
  where zzz is the path from the executable to the anchor point. At runtime
  dyld sets it run path to be the anchor point, then each dylib is found
  relative to the anchor point.

バイナリをリンクするときにパス-rpath path/containing/the/libraryして、共有ライブラリのロードコマンドでプレフィックスを展開するときに検索する場所を指定する必要があります。GHCを使用すると、引数を使用してフラグをに渡すことができるため、次のようにGHCを呼び出すことができます。ld@rpath/-optl-Wlld

ghc --make Main.hs mycbinding.o -ljvm -L<javahome>/jre/lib/server -optl-Wl,-rpath,<javahome>/jre/lib/server -o mybinary
于 2013-02-02T01:19:49.840 に答える