编译memcached时,报错没有libevent,于是下载libevent,configure , make && make install ,然后在重新安装memcache成功之后。memcached默认安装在/usr/local/bin/目录下。

执行命令 ./memcache -help 报错:

[root@localhost bin]# ./memcached
./memcached: error while loading shared libraries: libevent-2.0.so.: cannot open shared object file: No such file or directory

但是上面明明已经安装了 libevent 的,应该是memcached没有寻找到。

查找 libevent 安装的路径:

[root@localhost bin]# whereis libevent
libevent: /usr/local/lib/libevent.la /usr/local/lib/libevent.a /usr/local/lib/libevent.so

我们看到被安装到了:/usr/local/lib/libevent.so

我们查看 memcached 的依赖:

[root@localhost bin]# ldd /usr/local/bin/memcached
linux-gate.so. => (0x00c8d000)
libevent-2.0.so. => not found
librt.so. => /lib/librt.so. (0x00720000)
libpthread.so. => /lib/libpthread.so. (0x006fc000)
libc.so. => /lib/libc.so. (0x00564000)
/lib/ld-linux.so. (0x0053e000)

发现依赖的 libevent-2.0.so.5 => not found 没有找到。

查看 libevent 如何寻找依赖:

[root@localhost bin]# LD_DEBUG=libs ./memcached -v
: find library=libevent-2.0.so. []; searching
: search cache=/etc/ld.so.cache
: search path=/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:/lib/i686:/lib/sse2:/lib:/usr/lib/tls/i686/sse2:/usr/lib/tls/i686:/usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr/lib/i686:/usr/lib/sse2:/usr/lib (system search path)
: trying file=/lib/tls/i686/sse2/libevent-2.0.so.
: trying file=/lib/tls/i686/libevent-2.0.so.
: trying file=/lib/tls/sse2/libevent-2.0.so.
: trying file=/lib/tls/libevent-2.0.so.
: trying file=/lib/i686/sse2/libevent-2.0.so.
: trying file=/lib/i686/libevent-2.0.so.
: trying file=/lib/sse2/libevent-2.0.so.
: trying file=/lib/libevent-2.0.so.
: trying file=/usr/lib/tls/i686/sse2/libevent-2.0.so.
: trying file=/usr/lib/tls/i686/libevent-2.0.so.
: trying file=/usr/lib/tls/sse2/libevent-2.0.so.
: trying file=/usr/lib/tls/libevent-2.0.so.
: trying file=/usr/lib/i686/sse2/libevent-2.0.so.
: trying file=/usr/lib/i686/libevent-2.0.so.
: trying file=/usr/lib/sse2/libevent-2.0.so.
: trying file=/usr/lib/libevent-2.0.so.

我们看到:

search path=/lib/tls/i686/sse2:/lib/tls/i686:/lib/tls/sse2:/lib/tls:/lib/i686/sse2:
/lib/i686:/lib/sse2:/lib:/usr/lib/tls/i686/sse2:/usr/lib/tls/i686:
/usr/lib/tls/sse2:/usr/lib/tls:/usr/lib/i686/sse2:/usr/lib/i686:/usr/lib/sse2:/usr/lib (system search path)

系统寻找 lib 的路径,中没有包含:/usr/local/lib/

所以找到了原因,解决方法就很简单了。也有多种方法。

1) 做一个软连接到上面的随便一个 search path 中的目录都是可以的:

[root@localhost bin]# ln -s /usr/local/lib/libevent.so /usr/lib/libevent-2.0.so.

验证是否已经解决:

[root@localhost bin]# memcached -help
memcached 1.4.
-p <num> TCP port number to listen on (default: )
-U <num> UDP port number to listen on (default: , is off)
-s <file> UNIX socket path to listen on (disables network support)
-A enable ascii "shutdown" command
-a <mask> access mask for UNIX socket, in octal (default: )
-l <addr> interface to listen on (default: INADDR_ANY, all addresses)
<addr> may be specified as host:port. If you don't specify
a port number, the value you specified with -p or -U is
used. You may specify multiple addresses separated by comma
or by using -l multiple times
-d run as a daemon
-r maximize core file limit
-u <username> assume identity of <username> (only when run as root)
-m <num> max memory to use for items in megabytes (default: MB)
-M return error on memory exhausted (rather than removing items)
-c <num> max simultaneous connections (default: )
-k lock down all paged memory. Note that there is a
limit on how much memory you may lock. Trying to
allocate more than that would fail, so be sure you
set the limit correctly for the user you started
the daemon with (not for -u <username> user;
under sh this is done with 'ulimit -S -l NUM_KB').
-v verbose (print errors/warnings while in event loop)
-vv very verbose (also print client commands/reponses)
-vvv extremely verbose (also print internal state transitions)
-h print this help and exit
-i print memcached and libevent license
-V print version and exit
-P <file> save PID in <file>, only used with -d option
-f <factor> chunk size growth factor (default: 1.25)
-n <bytes> minimum space allocated for key+value+flags (default: )
-L Try to use large memory pages (if available). Increasing
the memory page size could reduce the number of TLB misses
and improve the performance. In order to get large pages
from the OS, memcached will allocate the total item-cache
in one large chunk.
-D <char> Use <char> as the delimiter between key prefixes and IDs.
This is used for per-prefix stats reporting. The default is
":" (colon). If this option is specified, stats collection
is turned on automatically; if not, then it may be turned on
by sending the "stats detail on" command to the server.
-t <num> number of threads to use (default: )
-R Maximum number of requests per event, limits the number of
requests process for a given connection to prevent
starvation (default: )
-C Disable use of CAS
-b Set the backlog queue limit (default: )
-B Binding protocol - one of ascii, binary, or auto (default)
-I Override the size of each slab page. Adjusts max item size
(default: 1mb, min: 1k, max: 128m)
-F Disable flush_all command
-o Comma separated list of extended or experimental options
- (EXPERIMENTAL) maxconns_fast: immediately close new
connections if over maxconns limit
- hashpower: An integer multiplier for how large the hash
table should be. Can be grown at runtime if not big enough.
Set this based on "STAT hash_power_level" before a
restart.
- tail_repair_time: Time in seconds that indicates how long to wait before
forcefully taking over the LRU tail item whose refcount has leaked.
Disabled by default; dangerous option.
- hash_algorithm: The hash table algorithm
default is jenkins hash. options: jenkins, murmur3
- lru_crawler: Enable LRU Crawler background thread
- lru_crawler_sleep: Microseconds to sleep between items
default is .
- lru_crawler_tocrawl: Max items to crawl per slab per run
default is (unlimited)
- lru_maintainer: Enable new LRU system + background thread
- hot_lru_pct: Pct of slab memory to reserve for hot lru.
(requires lru_maintainer)
- warm_lru_pct: Pct of slab memory to reserve for warm lru.
(requires lru_maintainer)
- expirezero_does_not_evict: Items set to not expire, will not evict.
(requires lru_maintainer)

我们看到没有报错了。

2) 在编译libevent的时候,指定相关目录:

[root@localhost libevent]# ./configure --help
`configure' configures this package to adapt to many kinds of systems. Usage: ./configure [OPTION]... [VAR=VALUE]... To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables. Defaults for the options are specified in brackets. Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..'] Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX] By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'. For better control, use the options below. Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/PACKAGE]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR] Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD] Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-dependency-tracking
do not reject slow dependency extractors
--disable-dependency-tracking
speeds up one-time build
--enable-gcc-warnings enable verbose warnings with GCC
--disable-thread-support
disable support for threading
--disable-malloc-replacement
disable support for replacing the memory mgt
functions
--disable-openssl disable support for openssl encryption
--disable-debug-mode disable support for running in debug mode
--disable-libevent-install, disable installation of libevent --disable-libevent-regress, skip regress in make check --enable-function-sections, make static library allow smaller binaries with --gc-sections --enable-shared[=PKGS] build shared libraries [default=yes]
--enable-static[=PKGS] build static libraries [default=yes]
--enable-fast-install[=PKGS]
optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds) Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use
both]
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
--with-sysroot=DIR Search for dependent libraries within DIR
(or the compiler's sysroot if not specified). Some influential environment variables:
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
nonstandard directory <lib dir>
LIBS libraries to pass to the linker, e.g. -l<library>
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations. Report bugs to the package provider.
Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX] By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'. For better control, use the options below. Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include] 所以我们可以如此的在configure时指定路径:
[root@localhost libevent]# ./configure --libdir=/usr/lib

3) 修改环境变量 LD_LIBRARY_PATH,将/usr/local/lib 包含进去。但是该方法一般不推荐这样做(但是有一种变通的做法,具体参见总结中的 3>)。

---------------------------------------------------------------------------------------------------------

总结:

1. 和共享库相关的一些错误如何处理:

1> LD_DEBUG 命令:

LD_DEBUG 是 glibc 中的 loader 为了方便自身调试而设置的一个环境变量。通过设置这个环境变量,可以方便的看到 loader 的加载过程。

[root@localhost libevent]# LD_DEBUG=help ls
Valid options for the LD_DEBUG environment variable are: libs display library search paths
reloc display relocation processing
files display progress for input file
symbols display symbol table processing
bindings display information about symbol binding
versions display version dependencies
all all previous options combined
statistics display relocation statistics
unused determined unused DSOs
help display this help message and exit To direct the debugging output into a file instead of standard output
a filename can be specified using the LD_DEBUG_OUTPUT environment variable.

上面列出了 LD_DEBUG 所有的选项,上面我们就使用了 LD_DEBUG=libs 。使用该命令可以获取很多有用的信息。

2> ldd - print shared library dependencies 打印输出依赖库

3> LD_LIBRARY_PATH, /etc/ld.so.conf.d,ldconfig

因为连接器会到目录 /etc/ld.so.conf.d 下面去寻找 配置了 共享库 的目录,所以根据这个原理,我们可以为 /usr/local/lib 专门建立一个配置文件

加入到连接器寻找 共享库 的目录列表中:

[root@localhost ld.so.conf.d]# pwd
/etc/ld.so.conf.d
[root@localhost ld.so.conf.d]# ls
kernel-2.6.-.el6.i686.conf mysql-i386.conf qt-i386.conf xulrunner-.conf
[root@localhost ld.so.conf.d]# echo "/usr/local/lib" > usr_local_lib.conf
[root@localhost ld.so.conf.d]# ll
total
-r--r--r--. root root Oct kernel-2.6.-.el6.i686.conf
-rw-r--r--. root root Feb mysql-i386.conf
-rw-r--r--. root root Sep qt-i386.conf
-rw-r--r--. root root Sep : usr_local_lib.conf
-rw-r--r--. root root Oct xulrunner-.conf
[root@localhost ld.so.conf.d]# cat usr_local_lib.conf
/usr/local/lib
[root@localhost ld.so.conf.d]# ldconfig

这样以后 /usr/local/lib 中的共享库就会被连接器寻找到,注意修改连接器相关的配置之后,一定要用 ldconfig 命令更新一下,不然还是找不到。

4> ln -s /usr/local/lib/libevent.so /usr/lib/libevent-2.0.so. 建立一个软连接

推荐方法:4 和 3。

2. 如何寻找文件,库等:

whereis - locate the binary, source, and manual page files for a command

updatedb - update a database for locate

locate - find files by name

find 命令 find - search for files in a directory hierarchy

示例: whereis libevent, updatedb, locate libevent,

find / -name libevent.*

[root@localhost bin]# find /usr/local -name libevent.*
/usr/local/redis-3.0./deps/hiredis/adapters/libevent.h
/usr/local/src/libevent/libevent.pc.in
/usr/local/src/libevent/libevent.pc
/usr/local/lib/libevent.la
/usr/local/lib/libevent.a
/usr/local/lib/pkgconfig/libevent.pc
/usr/local/lib/libevent.so [root@localhost bin]# find / -name libevent.so
/usr/local/lib/libevent.so
[root@localhost bin]# find / -name libevent.so*
/usr/local/lib/libevent.so

find 命令 第一个参数是查找的路径 /usr/local 第二个参数是要查找的文件名的表达式,可以使用正则表达式来表示查找的文件名。

find 还有一个常见的用法:对找到的文件执行某个命令:

find . -name \*.lo -o -name \*.o | xargs rm -f    (xargs - build and execute command lines from standard input)

3. configure 之前一定要 configure --help 查看配置选项。

Linux 下编译安装软件,找不到共享库 xx.so 的解决办法的更多相关文章

  1. linux安装软件的几种方法----linux下编译安装软件的一般步骤

    linux安装软件的几种方法: 一.rpm包安装方式步骤: 1.找到相应的软件包,比如soft.version.rpm,下载到本机某个目录: 2.打开一个终端,su -成root用户: 3.cd so ...

  2. linux下编译安装vim7.4并安装clang_complete插件

    linux下编译安装vim7.4并安装clang_complete插件 因为debian里软件仓库中下载安装的vim是不支持python写的插件的(可以打开vim,在命令模式先输入:py测试一下),导 ...

  3. Linux下编译安装qemu和libvirt

    目录 [hide] 1 安装qemu 1.1 qemu介绍 1.2 下载源文件 1.3 编译安装 2 安装libvirt 2.1 libvirt介绍 2.2 下载libvirt 2.3 编译安装 3  ...

  4. Linux 下如何安装软件?

    http://zhidao.baidu.com/link?url=OkQCOZtVMXhasC8x9zFTZOumsFKf0WW25Ckr2wBF1xO08EsjrBpnMaTBlIAUYdxZ408 ...

  5. Linux下编译安装qemu和libvirt【转】

    转自:http://www.cnblogs.com/findumars/p/5679742.html 目录 [hide] 1 安装qemu 1.1 qemu介绍 1.2 下载源文件 1.3 编译安装 ...

  6. LINUX下编译安装PHP各种报错大集合

    本文为大家整理汇总了一些linux下编译安装php各种报错大集合 ,感兴趣的同学参考下. nginx1.6.2-mysql5.5.32二进制,php安装报错解决: 123456 [root@clien ...

  7. linux下编译安装curl

    linux下编译安装curl 1.下载curl git clone https://github.com/curl/curl.git 2.在curl目录下生成configure文件 ./buldcon ...

  8. linux下编译安装boost库

    linux下编译安装boost库 linux下编译安装boost库 1.下载并解压boost 1.58 源代码 下载 解压 2.运行bootstrap.sh 3.使用b2进行构建 构建成功的提示 4. ...

  9. Linux下编译安装Apache Http Server

    Linux下编译安装Apache Http Server [TOC] 1.下载httpd-2.4.12.tar.bz2 wget http://mirror.bit.edu.cn/apache/htt ...

随机推荐

  1. 安装DRBD的一些问题

    安装DRBD,建议用源代码包先生成rpm包来安装,不要用直接download的rpm包,有可能会用不了,因为这跟系统内核版本有关系,在2.6.33版本以前内核没有集成drbd,   A.先安装一些其它 ...

  2. 高级四则运算器—结对项目总结(193 &105)

    高级四则运算器—结对项目总结 为了将感想与项目经验体会分割一下,特在此新开一篇博文. 界面设计 啥都不说,先上图震慑一下... 上面的三个界面是我们本次结对项目的主界面,恩,我也觉得挺漂亮的!你问我界 ...

  3. [ASP.NET] 下一代ASP.NET开发规范:OWIN

    今天投简历 准备面试了... 本节目录: OWIN简介 OWIN规范 Katana Hello World(3种Host) 自定义Middleware OWIN简介 OWIN(Open Web Int ...

  4. [Bootstrap]7天深入Bootstrap(1)入门准备

    由于申请了一个域名,一个云主机,开始弄个人网站. 发现Bootstrap非常方便,和重要,故开始学习与分享关于Bootstrap的技术. 推个广告 个人网站:http://www.neverc.cn ...

  5. ADO.NET学习系列(二)

    这次我使用ADO.NET来插入一条数据,到数据库中.主用到存储过程.我不想每次都是用SQL文本的形式了,那样始终没有进步--- 下面首先,我把我这次练习要用到的数据库脚本,贴出来: USE maste ...

  6. C#设计模式——抽象工厂模式(Abstract Factory Pattern)

    一.概述在软件开发中,常常会需要创建一系列相互依赖的对象,同时,由于需求的变化,往往存在较多系列对象的创建工作.如果采用常规的创建方法(new),会造成客户程序和对象创建工作的紧耦合.对此,抽象工厂模 ...

  7. C#的Raw Socket实现网络封包监视

    同Winsock1相比,Winsock2最明显的就是支持了Raw Socket套接字类型,使用Raw Socket,可把网卡设置成混杂模式,在这种模式下,我们可以收到网络上的IP包,当然包括目的不是本 ...

  8. ubuntu 14.04 64位安装bigbluebutton

    BigBlueButton 是一个使用 ActionScript 开发的在线视频会议系统或者是远程教育系统,主要功能包括在线PPT演示.视频交流和语音交流,还可以进行文字交流.举手发言等功能,特别适合 ...

  9. string.join加引号

    columnsGen = string.Join(",", modelDictionary.Keys); valueGen = modelDictionary.Values.Agg ...

  10. HttpClient总结一之基本使用

    最近工作中是做了一个handoop的hdfs系统的文件浏览器的功能,是利用webhdfs提供的rest api来访问hdfs来与hdfs进行交互的,其中大量使用HttpClient,之前一直很忙,没什 ...