2013-02-01 18 views
10

libjvm ile bağlantı gerektiren bir uygulama var (JDN'den JNI bağlamaları yapmak için gereken bir kitaplık). libjvm.dylib konumunu -L kullanarak anlattığımda, başarıyla derler ve bağlantılar.Bir dinamik kitaplığı (libjvm.dylib) Mac OS X'e bağlama (rpath issue)

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

Şimdiye kadar ben şöyle benim ikili belirten LD_LIBRARY_PATH çalıştırabilirsiniz öğrendim:

LD_LIBRARY_PATH=<path to libfolder installation> ./mybinary 

Ama tabii ben bunu istemiyorum ben ikili çalıştırdığınızda Ancak olsun. Uygulamayı her başlattığımda tekrar tekrar vermem gerekirse, neden tam konumu belirtmeliyim ?!

Ayrıca, mac os x üzerindeki dinamik kitaplıkların, konumu söyleyen bir tür damga aldığını öğrendim. Ancak, rpath'un ne olduğunu bilmiyorum (bana bir değişken gibi görünüyor, ancak bağlantı sırasında bunu nasıl ayarlayabilirim?).

Uygulama, haskell kullanılarak oluşturulmuştur, ancak ld'u kullanarak nesne dosyalarını eşit olarak iyi bir şekilde bağlayabiliyorum. Ancak, bu rpath şeyine takılıyorum - belki de JDK kütüphaneleri için özel mi?

Apple'ın dyld man page itibaren
ghc --make Main.hs mycbinding.o -ljvm -L<javahome>/jre/lib/server -o mybinary 

cevap

10

: Burada

Ben inşa etmek için yapması gereken şeydir @

rpath/Sen ld için -rpath path/containing/the/library geçmesi gerekiyor

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. 

nerede olduğunu söylemek için ikili bağlandığında Paylaşılan kitaplık yükleme komutunda @rpath/ önekini genişletirken kemer. Ghc ile bu ld kadar bayraklar geçmesi için -optl-Wl argüman kullanabilirsiniz, bu nedenle şöyle ghc çağırmak istersiniz:

ghc --make Main.hs mycbinding.o -ljvm -L<javahome>/jre/lib/server -optl-Wl,-rpath,<javahome>/jre/lib/server -o mybinary