2011-11-23 76 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' –