系统为Linux debian 2.6.32-5-686。这是裸系统,连xwindows都没有。帐户为root,不是的注意一下权限。这里想说明安装过程及出现的问题,故打印的信息较多,以供出现错误的读者对比。不需要这些信息的读者勿喷。

  网上流行的安装方法:

sh autogen.sh 或 ./configure

make

make install

注意,sh autogen.sh 或 ./configure 只运行其中一个就可以,功能一样。只是autogen.sh调用autoconf来配置参数,./configure就不多说了。配置libev时,两者打印的信息基本是一样了。如果用./configure,就不用安装autoconf之类的了。

  下面以sh autogen.sh的方法来安装。先安装autoconf,因为autogen.sh需要。

root@debian:/home/xzc/cpp/libev-4.15# cat autogen.sh
#!/bin/sh autoreconf --install --symlink --force
root@debian:/home/xzc/cpp/libev-4.15# apt-get install autoconf
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
automake autotools-dev
Suggested packages:
autoconf2. autoconf-archive gnu-standards autoconf-doc libtool gettext
The following NEW packages will be installed:
autoconf automake autotools-dev
upgraded, newly installed, to remove and not upgraded.
Need to get kB of archives.
After this operation, kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get: http://debian.nctu.edu.tw/debian/ squeeze/main autoconf all 2.67-2 [793 kB]
Get: http://debian.nctu.edu.tw/debian/ squeeze/main autotools-dev all 20100122.1 [71.9 kB]
Get: http://debian.nctu.edu.tw/debian/ squeeze/main automake all 1:1.11.1-1+squeeze1 [611 kB]
Fetched kB in 2s ( kB/s)
Selecting previously deselected package autoconf.
(Reading database ... files and directories currently installed.)
Unpacking autoconf (from .../autoconf_2.-2_all.deb) ...
Selecting previously deselected package autotools-dev.
Unpacking autotools-dev (from .../autotools-dev_20100122.1_all.deb) ...
Selecting previously deselected package automake.
Unpacking automake (from .../automake_1%3a1.11.1-+squeeze1_all.deb) ...
Processing triggers for man-db ...
Processing triggers for install-info ...
Setting up autoconf (2.67-) ...
Setting up autotools-dev (20100122.1) ...
Setting up automake (:1.11.-+squeeze1) ...
update-alternatives: using /usr/bin/automake-1.11 to provide /usr/bin/automake (automake) in auto mode

可以看到,系统还一起安装了automake。现在再运行sh autogen.sh

root@debian:/home/xzc/cpp/libev-4.15# sh autogen.sh
configure.ac:: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status:

看来还缺了libtool,那就装一个呗

root@debian:/home/xzc/cpp/libev-4.15# apt-get install libtool
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
binutils cpp cpp-4.4 gcc gcc-4.4 libc-dev-bin libc6-dev libgmp3c2 libgomp1 libltdl-dev libltdl7 libmpfr4 linux-libc-dev manpages-dev
Suggested packages:
binutils-doc cpp-doc gcc-4.4-locales gcc-multilib make automake1. flex bison gdb gcc-doc gcc-4.4-multilib libmudflap0-4.4-dev gcc-4.4-doc
libgcc1-dbg libgomp1-dbg libmudflap0-dbg libcloog-ppl0 libppl-c2 libppl7 glibc-doc libtool-doc gfortran fortran95-compiler gcj
The following NEW packages will be installed:
binutils cpp cpp-4.4 gcc gcc-4.4 libc-dev-bin libc6-dev libgmp3c2 libgomp1 libltdl-dev libltdl7 libmpfr4 libtool linux-libc-dev manpages-dev
upgraded, newly installed, to remove and not upgraded.
Need to get kB/19.5 MB of archives.
After this operation, 55.8 MB of additional disk space will be used.

现在再来sh autogen.sh

root@debian:/home/xzc/cpp/libev-4.15# sh autogen.sh
libtoolize: putting auxiliary files in `.'.
libtoolize: linking file `./ltmain.sh'
libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.ac and
libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
root@debian:/home/xzc/cpp/libev-4.15# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... no
checking whether to enable maintainer-specific portions of Makefiles... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... none
checking dependency style of gcc... none
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments...
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for ar... ar
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking sys/inotify.h usability... yes
checking sys/inotify.h presence... yes
checking for sys/inotify.h... yes
checking sys/epoll.h usability... yes
checking sys/epoll.h presence... yes
checking for sys/epoll.h... yes
checking sys/event.h usability... no
checking sys/event.h presence... no
checking for sys/event.h... no
checking port.h usability... no
checking port.h presence... no
checking for port.h... no
checking poll.h usability... yes
checking poll.h presence... yes
checking for poll.h... yes
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking sys/eventfd.h usability... yes
checking sys/eventfd.h presence... yes
checking for sys/eventfd.h... yes
checking sys/signalfd.h usability... yes
checking sys/signalfd.h presence... yes
checking for sys/signalfd.h... yes
checking for inotify_init... yes
checking for epoll_ctl... yes
checking for kqueue... no
checking for port_create... no
checking for poll... yes
checking for select... yes
checking for eventfd... yes
checking for signalfd... yes
checking for clock_gettime... no
checking for clock_gettime syscall... yes
checking for nanosleep... yes
checking for library containing floor... -lm
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands

看来结果OK,然后make,才发现连make都没安装,那就apt-get install make。看一下make的结果

root@debian:/home/xzc/cpp/libev-4.15# make
make all-am
make[]: Entering directory `/home/xzc/cpp/libev-4.15'
source='ev.c' object='ev.lo' libtool=yes \
DEPDIR=.deps depmode=none /bin/bash ./depcomp \
/bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -g -O3 -c -o ev.lo ev.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -g -O3 -c ev.c -fPIC -DPIC -o .libs/ev.o
ev.c:: warning: 'ev_default_loop_ptr' initialized and declared 'extern'
libtool: compile: gcc -DHAVE_CONFIG_H -I. -g -O3 -c ev.c -o ev.o >/dev/null >&
source='event.c' object='event.lo' libtool=yes \
DEPDIR=.deps depmode=none /bin/bash ./depcomp \
/bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -g -O3 -c -o event.lo event.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -g -O3 -c event.c -fPIC -DPIC -o .libs/event.o
libtool: compile: gcc -DHAVE_CONFIG_H -I. -g -O3 -c event.c -o event.o >/dev/null >&
/bin/bash ./libtool --tag=CC --mode=link gcc -g -O3 -version-info :: -o libev.la -rpath /usr/local/lib ev.lo event.lo -lm
libtool: link: gcc -shared .libs/ev.o .libs/event.o -lm -Wl,-soname -Wl,libev.so. -o .libs/libev.so.4.0.
libtool: link: (cd ".libs" && rm -f "libev.so.4" && ln -s "libev.so.4.0.0" "libev.so.4")
libtool: link: (cd ".libs" && rm -f "libev.so" && ln -s "libev.so.4.0.0" "libev.so")
libtool: link: ar cru .libs/libev.a ev.o event.o
libtool: link: ranlib .libs/libev.a
libtool: link: ( cd ".libs" && rm -f "libev.la" && ln -s "../libev.la" "libev.la" )

现在看看make install的结果

root@debian:/home/xzc/cpp/libev-4.15# make install
make[]: Entering directory `/home/xzc/cpp/libev-4.15'
test -z "/usr/local/lib" || /bin/mkdir -p "/usr/local/lib"
/bin/bash ./libtool --mode=install /usr/bin/install -c libev.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libev.so.4.0. /usr/local/lib/libev.so.4.0.
libtool: install: (cd /usr/local/lib && { ln -s -f libev.so.4.0. libev.so. || { rm -f libev.so. && ln -s libev.so.4.0. libev.so.; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libev.so.4.0. libev.so || { rm -f libev.so && ln -s libev.so.4.0. libev.so; }; })
libtool: install: /usr/bin/install -c .libs/libev.lai /usr/local/lib/libev.la
libtool: install: /usr/bin/install -c .libs/libev.a /usr/local/lib/libev.a
libtool: install: chmod /usr/local/lib/libev.a
libtool: install: ranlib /usr/local/lib/libev.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for
more information, such as the ld() and ld.so() manual pages.
----------------------------------------------------------------------
test -z "/usr/local/include" || /bin/mkdir -p "/usr/local/include"
/usr/bin/install -c -m ev.h ev++.h event.h '/usr/local/include'
test -z "/usr/local/share/man/man3" || /bin/mkdir -p "/usr/local/share/man/man3"
/usr/bin/install -c -m ev. '/usr/local/share/man/man3'
make[]: Leaving directory `/home/xzc/cpp/libev-4.15'

注意,里面还是有些有用的信息的,如

Libraries have been installed in:
/usr/local/lib

写了一段代码来测试

#include <ev.h>
#include <stdio.h> ev_io stdin_watcher;
ev_timer timeout_watcher; static void stdin_cb(EV_P_ ev_io *w,int revents)
{
puts ("stdin ready");
ev_io_stop(EV_A_ w);
ev_break (EV_A_ EVBREAK_ALL);
} static void timeout_cb (EV_P_ ev_timer *w,int revents)
{
puts ("timeout");
ev_break( EV_A_ EVBREAK_ONE );
} int main(int argc,char* argv[])
{
struct ev_loop *loop = EV_DEFAULT; ev_io_init(&stdin_watcher,stdin_cb,,EV_READ);
ev_io_start (loop,&stdin_watcher); ev_timer_init (&timeout_watcher,timeout_cb,5.5,); // in document the last is 0. not 0,I don't know why yet
ev_timer_start (loop,&timeout_watcher); ev_run (loop,); return ;
} output:
root@debian:/home/xzc/cpp/test# gcc -o libev_hello libev_hello.c
/tmp/ccNN2QkE.o: In function `stdin_cb':
libev_hello.c:(.text+0x20): undefined reference to `ev_io_stop'
libev_hello.c:(.text+0x33): undefined reference to `ev_break'
/tmp/ccNN2QkE.o: In function `timeout_cb':
libev_hello.c:(.text+0x5a): undefined reference to `ev_break'
/tmp/ccNN2QkE.o: In function `main':
libev_hello.c:(.text+0x71): undefined reference to `ev_default_loop'
libev_hello.c:(.text+0xc9): undefined reference to `ev_io_start'
libev_hello.c:(.text+0x11f): undefined reference to `ev_timer_start'
libev_hello.c:(.text+0x133): undefined reference to `ev_run'
collect2: ld returned exit status

试一下只编译不连接gcc -c -o libev_hello libev_hello.c,没有错误,看来是link时没有找到库

尝试连接时指定需要libev库,gcc -o libev_hello libev_hello.c -lev,没有问题。但:

root@debian:/home/xzc/cpp/test# gcc -o libev_hello libev_hello.c -lev
root@debian:/home/xzc/cpp/test# ./libev_hello
./libev_hello: error while loading shared libraries: libev.so.: cannot open shared object file: No such file or directory

看来编译链接时指定了,可运行时没呢。另外,为什么要加-lev呢,参考gcc的参数-llibrary

-llibrary

  制定编译的时候使用的库

  例子用法

  gcc -lcurses hello.c

  使用ncurses库编译程序

所以-lev中-l是参数类型,ev才是libev的库名称,不信看文件命名:ev.h ev++.h

查看/usr/local/lib下的内容:

root@debian:/usr/local/lib# ls -lh
total 368K
-rw-r--r-- root staff 213K May : libev.a
-rwxr-xr-x root staff May : libev.la
lrwxrwxrwx root staff May : libev.so -> libev.so.4.0.
lrwxrwxrwx root staff May : libev.so. -> libev.so.4.0.
-rwxr-xr-x root staff 133K May : libev.so.4.0.
drwxrwsr-x root staff .0K Sep python2.

解决运行的问题,仔细看make install时产生的信息:

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'

有N多种呢,下面是一种

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib 写到~/.bash_profile里面,就不用每次都要export了。

gcc -o libev_hello libev_hello.c -lev

./libev_hello

运行OK

debian下编译libev库的更多相关文章

  1. 在Ubuntu下编译Assimp库

    在Ubuntu下编译Assimp库 怎样在Ubuntu下编译Assimp库?这是我曾经编译成功后做的笔记,供參考. 1.去以下的站点去下载Assimp库: http://assimp.sourcefo ...

  2. 001.libev安装及eclipse下添加libev库链接

    libev库安装: 1.下载页面:http://dist.schmorp.de/libev/ 当前版本下载: [root@mid_server ~]# cd /usr/local/src  [root ...

  3. debian下编译安装poco

    系统环境: debian版本:Linux localhost.localdomain 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC ...

  4. Windows环境下编译Assimp库生成Android可用的.so或.a文件

    在做项目过程中需要使用Assimp这个3D模型读取库来读取obj格式的模型,因为项目是基于Android平台,采用NDK开发,所以就打算编译Assimp库并生成.so文件.本文使用Assimp-v.5 ...

  5. Linux下 编译lib3ds库

    从网上下载的一个QT程序链接需要用到lib3ds.a静态库. lib3ds is an overall software library for managing 3D-Studio Release ...

  6. Ubuntu下编译Poco库

    本文主要记录下Ubuntu下编译Poco C++库的配置项以备后用.系统版本:Ubuntu 16.04,1 Poco 版本:1.9.0基本的步骤如下: 1.从官网下载最新的Poco源码,地址是:htt ...

  7. Debian下编译安装驱动模块

    在Linux下,我们常有需要自己来编译安装驱动模块的情况,例如要安装显卡驱动,要安装无线驱动,有的时候某个程序的安装使用与需要安装相应的驱动模块.Debian Linux下的生活本已十分简单,使用ap ...

  8. Linux下编译第三方库的问题

    因为各个Linux发行版之间的差异还是挺大的,有一些预安装在系统上的基本库是不一样的(不仅仅是版本,有一些是有和无的区别). 那么问题来了: 编译第三方库./configure的时候一般我们不会定制那 ...

  9. debian下编译openwrt固件

    参考文章:Ubuntu下编译OpenWRT固件 我买的路由器是RG100A-AA,采用了bcm63xx系列的芯片. 下载openwrt源码: svn co svn://svn.openwrt.org/ ...

随机推荐

  1. poj 3104 Drying(二分搜索之最大化最小值)

    Description It is very hard to wash and especially to dry clothes in winter. But Jane is a very smar ...

  2. 为人们服务的asp.net 验证控件

    ASP.NET是微软推出的WEB开发工具,他有很强大的功能,今天看视频讲到验证控件这一部分,真的感受到了微软全心全意为人民服务了.越来越佩服微软了,人家都设计出来了,咱们一定要会用才可以啊,不然太…. ...

  3. hdu1015(Safecracker )

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...

  4. 使用WinAPI全局热键注册和全局模拟按键

    一.全局热键注册 1.先引用DLL [System.Runtime.InteropServices.DllImport("user32.dll")] //导入WinAPI publ ...

  5. Java ----------- SQL语句总结(更新中。。。。。。)

    #对数据库的操作 *创建数据库 CREATE DATABASE database_name:database_name为创建的数据库的变量名称. #对表的操作

  6. BZOJ 1001 狼抓兔子 (网络流最小割/平面图的对偶图的最短路)

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1001 算法讨论: 1.可以用最大流做,最大流等于最小割. 2.可以把这个图转化其对偶图,然 ...

  7. [转载]opencv +linux

    转载 ubuntu12.04安装openCV2.4.2(2012-08-08 16:54:06 参考http://www.samontab.com/web/2012/06/installing-ope ...

  8. Qt将表格table保存为excel(odbc方式)

    首先是保存excel的方法,可参照: http://dzmlmszp.blog.163.com/blog/static/179271962014819111812531/ ok,进入正题. 现在我有一 ...

  9. shell中的if语句

    语法格式 if command;then commands fi 其中的command包含如下: shell command 任何shell命令,如果shell命令返回0,代表true,否则,代表fa ...

  10. CSSOM视图模式

    相关技术文章: CSSOM视图模式(CSSOM View Module)相关整理 W3C CSSOM View Module