2011-11-23 22 views
4

有這樣的代碼:錯誤運行與共享庫的程序時

#include <cstdlib> 
#include <clang-c/Index.h> 

using namespace std; 

int main(int argc, char** argv) 
{ 
    CXIndex Index = clang_createIndex(0, 0); 
    CXTranslationUnit TU = clang_parseTranslationUnit(Index, 0, argv, argc, 0, 0, CXTranslationUnit_None); 
    for (unsigned I = 0, N = clang_getNumDiagnostics(TU); I != N; ++I) 
    { 
     CXDiagnostic Diag = clang_getDiagnostic(TU, I); 
     CXString String = clang_formatDiagnostic(Diag, 
       clang_defaultDiagnosticDisplayOptions()); 
     fprintf(stderr, "%s\n", clang_getCString(String)); 
     clang_disposeString(String); 
    } 
    clang_disposeTranslationUnit(TU); 

    clang_disposeIndex(Index); 

    return 0; 
} 

而且它具有以下標誌編譯:

g++ main.cpp -g -fno-rtti `llvm-config --cxxflags --ldflags --libs` -lclang -o main 

但是當我要運行主:

./main 

則出現以下錯誤:

./main: error while loading shared libraries: libclang.so: cannot open shared object file: No such file or directory 

但是:

$ sudo find/-name libclang.so 
/usr/local/lib/libclang.so 

庫似乎是在地方。如何運行這個程序?

回答

4

ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib)

嘗試運行/sbin/ldconfig,然後如果不行嘗試用 「的/ usr/local/lib目錄」,然後運行/sbin/ldconfig

命令附加文件/etc/ld.so.conf:

  1. 運行以下命令,然後嘗試編譯/重新運行

    /sbin目錄/ LDCONFIG

  2. 如果不工作,然後做到這一點,然後嘗試編譯/重新運行

    回聲 「的/ usr/local/lib目錄」 >> /etc/ld.so.conf中 /sbin目錄/ LDCONFIG

+0

謝謝,它適用於我,用sudo:'sudo/sbin/ldconfig' –

相關問題