2012-08-17 77 views
3

我在辦公室使用libevent 2.X。在家我有提供libevent 1.4的Ubuntu 10.4,所以我下載並編譯了最新版本的libevent。現在我在/ usr/local/lib目錄下有/ usr/local/include和庫文件。但我的問題是,可執行文件似乎沒有找到正確的庫。g ++可執行文件找不到共享庫

我想這

[email protected]:~/development/Server/test$ g++ Server.cpp -L /usr/local/lib -levent -I /usr/local/include/ 

[email protected]:~/development/Server/test$ ./a.out 
./a.out: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory 

編制的詳細輸出低於

[email protected]:~/development/Server/test$ g++ Server.cpp -L /usr/local/lib -levent -I /usr/local/include/ -v 
Using built-in specs. 
Target: i486-linux-gnu 
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu 
Thread model: posix 
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) 
COLLECT_GCC_OPTIONS='-L' '/usr/local/lib' '-I' '/usr/local/include/' '-v' '-shared-libgcc' '-mtune=generic' '-march=i486' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/cc1plus -quiet -v -I /usr/local/include/ -D_GNU_SOURCE Server.cpp -D_FORTIFY_SOURCE=2 -quiet -dumpbase Server.cpp -mtune=generic -march=i486 -auxbase Server -version -fstack-protector -o /tmp/cceeQ3Uc.s 
GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (i486-linux-gnu) 
    compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1. 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu" 
ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../i486-linux-gnu/include" 
ignoring nonexistent directory "/usr/include/i486-linux-gnu" 
ignoring duplicate directory "/usr/local/include/" 
    as it is a non-system directory that duplicates a system directory 
#include "..." search starts here: 
#include <...> search starts here: 
/usr/include/c++/4.4 
/usr/include/c++/4.4/i486-linux-gnu 
/usr/include/c++/4.4/backward 
/usr/local/include 
/usr/lib/gcc/i486-linux-gnu/4.4.3/include 
/usr/lib/gcc/i486-linux-gnu/4.4.3/include-fixed 
/usr/include 
End of search list. 
GNU C++ (Ubuntu 4.4.3-4ubuntu5) version 4.4.3 (i486-linux-gnu) 
    compiled by GNU C version 4.4.3, GMP version 4.3.2, MPFR version 2.4.2-p1. 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
Compiler executable checksum: 35224f2c24023afb0a5be7befe8d5f3f 
COLLECT_GCC_OPTIONS='-L' '/usr/local/lib' '-I' '/usr/local/include/' '-v' '-shared-libgcc' '-mtune=generic' '-march=i486' 
as -V -Qy -o /tmp/cclpymAs.o /tmp/cceeQ3Uc.s 
GNU assembler version 2.20.1 (i486-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.20.1-system.20100303 
COMPILER_PATH=/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/ 
LIBRARY_PATH=/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/4.4.3/:/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../:/lib/:/usr/lib/:/usr/lib/i486-linux-gnu/ 
COLLECT_GCC_OPTIONS='-L' '/usr/local/lib' '-I' '/usr/local/include/' '-v' '-shared-libgcc' '-mtune=generic' '-march=i486' 
/usr/lib/gcc/i486-linux-gnu/4.4.3/collect2 --build-id --eh-frame-hdr -m elf_i386 --hash-style=both -dynamic-linker /lib/ld-linux.so.2 -z relro /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crti.o /usr/lib/gcc/i486-linux-gnu/4.4.3/crtbegin.o -L /usr/local/lib -L/usr/lib/gcc/i486-linux-gnu/4.4.3 -L/usr/lib/gcc/i486-linux-gnu/4.4.3 -L/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/i486-linux-gnu/4.4.3/../../.. -L/usr/lib/i486-linux-gnu /tmp/cclpymAs.o -levent -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/i486-linux-gnu/4.4.3/crtend.o /usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crtn.o 

回答

5

在運行時,動態可執行文件是動態鏈接ld.so再掛。就像您必須通過-L/usr/local/libgcc連接器才能在編譯時查找您的libray一樣,您必須通過ld.so.conf或通過環境變量LD_LIBRARY_PATH(例如,)來告訴ld.so關於您的異常搜索路徑。

LD_LIBRARY_PATH=/usr/local/lib ./a.out 

TL,手冊的DR:ldd會給你什麼樣的動態鏈接器會做一個概述,並且不要忘記改變ld.so.conf後運行ldconfig