2011-01-19 89 views
1

我在寫一個程序,它有兩個我需要使用的庫:v8和v8-juice。不幸的是,v8-juice不能被編譯爲一個靜態庫,因爲它使用了模板。還有一些需要將v8編譯爲共享對象的怪癖。共享對象和包含沒有安裝在Linux下的C++

所以,當我編譯我的程序時,最終有兩個可執行文件需要運行的共享對象。我的問題是,有沒有一種方法可以包含這些共享對象,而無需在Linux下進行安裝?對不起,如果這是一個新手問題,我對C++來說還很陌生。

回答

5

共享庫可以與您的可執行文件位於同一個文件夾中。 man ld.so:

$ORIGIN and rpath 

    ld.so understands the string $ORIGIN (or equivalently ${ORIGIN}) in an 
    rpath specification (DT_RPATH or DT_RUNPATH) to mean the directory con- 
    taining the application executable. Thus, an application located in 
    somedir/app could be compiled with gcc -Wl,-rpath,'$ORIGIN/../lib' so 
    that it finds an associated shared library in somedir/lib no matter 
    where somedir is located in the directory hierarchy. This facilitates 
    the creation of "turn-key" applications that do not need to be 
    installed into special directories, but can instead be unpacked into 
    any directory and still find their own shared libraries. 
+0

好的解決方案。缺點是'$ ORIGIN'這個詞的可怕選擇,它需要在每個shell和構建系統中進行某種轉義。 – ephemient 2011-01-19 23:47:51