2013-02-01 53 views
10

में एक गतिशील लाइब्रेरी (libjvm.dylib) को जोड़ना मेरे पास एक ऐसा एप्लिकेशन है जिसके लिए libjvm (जेडीआई बाइंडिंग करने के लिए आवश्यक जेडीके से लाइब्रेरी) की आवश्यकता है। जब मैं 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 

लेकिन निश्चित रूप से मुझे लगता है कि नहीं करना चाहती। मुझे हर बार सही स्थान निर्दिष्ट क्यों करना चाहिए यदि मुझे आवेदन शुरू करने पर हर बार इसे बार-बार देना है ?!

मैंने यह भी सीखा कि मैक ओएस एक्स पर गतिशील पुस्तकालयों को एक प्रकार का टिकट मिलता है जो वहां स्थान बताता है। हालांकि मुझे नहीं पता कि rpath क्या है (मेरे लिए एक चर जैसा लगता है, लेकिन मैं इसे जोड़ने के दौरान कैसे सेट कर सकता हूं?)।

एप्लिकेशन हैकेल का उपयोग करके बनाया गया है, लेकिन मैं ld का उपयोग कर ऑब्जेक्ट फ़ाइलों को मैन्युअल रूप से अच्छी तरह से लिंक कर सकता हूं। हालांकि, मैं उस आरपीएथ चीज पर फंस गया हूं - क्या यह शायद जेडीके पुस्तकालयों के लिए विशेष है?

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

उत्तर

10

से एप्पल के dyld man page:

यहाँ है कि मैं क्या आदेश का निर्माण करने में क्या है

@ 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. 

आप ld को -rpath path/containing/the/library पास करनी होगी जब आप अपने बाइनरी को यह कहने के लिए जोड़ते हैं कि कहां से है साझा लाइब्रेरी लोड कमांड में @rpath/ उपसर्ग का विस्तार करते समय आर्क। GHC के साथ आप यह ld के माध्यम से झंडे पारित करने के लिए -optl-Wl तर्क का उपयोग कर सकते हैं, ताकि आप तो जैसे GHC आह्वान करने के लिए चाहता हूँ:

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

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^