debian下编译libev库

  系统为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需要。


[email protected]:/home/xzc/cpp/libev-4.15# cat autogen.sh
#!/bin/sh

autoreconf --install --symlink --force
[email protected]:/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.13 autoconf-archive gnu-standards autoconf-doc libtool gettext
The following NEW packages will be installed:
autoconf automake autotools-dev
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1476 kB of archives.
After this operation, 4387 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://debian.nctu.edu.tw/debian/ squeeze/main autoconf all 2.67-2 [793 kB]
Get:2 http://debian.nctu.edu.tw/debian/ squeeze/main autotools-dev all 20100122.1 [71.9 kB]
Get:3 http://debian.nctu.edu.tw/debian/ squeeze/main automake all 1:1.11.1-1+squeeze1 [611 kB]
Fetched 1476 kB in 2s (493 kB/s)
Selecting previously deselected package autoconf.
(Reading database ... 24937 files and directories currently installed.)
Unpacking autoconf (from .../autoconf_2.67-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-1+squeeze1_all.deb) ...
Processing triggers for man-db ...
Processing triggers for install-info ...
Setting up autoconf (2.67-2) ...
Setting up autotools-dev (20100122.1) ...
Setting up automake (1:1.11.1-1+squeeze1) ...
update-alternatives: using /usr/bin/automake-1.11 to provide /usr/bin/automake (automake) in auto mode

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

[email protected]:/home/xzc/cpp/libev-4.15# sh autogen.sh
configure.ac:21: 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: 1

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


[email protected]:/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.9 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
0 upgraded, 15 newly installed, 0 to remove and 26 not upgraded.
Need to get 856 kB/19.5 MB of archives.
After this operation, 55.8 MB of additional disk space will be used.

现在再来sh autogen.sh

[email protected]:/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.
[email protected]:/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... 1572864
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的结果


[email protected]:/home/xzc/cpp/libev-4.15# make
make all-am
make[1]: 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:1531: 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 2>&1
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 2>&1
/bin/bash ./libtool --tag=CC --mode=link gcc -g -O3 -version-info 4:0:0 -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.4 -o .libs/libev.so.4.0.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的结果


[email protected]:/home/xzc/cpp/libev-4.15# make install
make[1]: 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.0 /usr/local/lib/libev.so.4.0.0
libtool: install: (cd /usr/local/lib && { ln -s -f libev.so.4.0.0 libev.so.4 || { rm -f libev.so.4 && ln -s libev.so.4.0.0 libev.so.4; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libev.so.4.0.0 libev.so || { rm -f libev.so && ln -s libev.so.4.0.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 644 /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(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/usr/local/include" || /bin/mkdir -p "/usr/local/include"
/usr/bin/install -c -m 644 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 644 ev.3 ‘/usr/local/share/man/man3‘
make[1]: 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,0,EV_READ);
ev_io_start (loop,&stdin_watcher);

ev_timer_init (&timeout_watcher,timeout_cb,5.5,0); // in document the last is 0. not 0,I don‘t know why yet
ev_timer_start (loop,&timeout_watcher);

ev_run (loop,0);

return 0;
}

output:
[email protected]:/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 1 exit status

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

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

[email protected]:/home/xzc/cpp/test# gcc -o libev_hello libev_hello.c -lev
[email protected]:/home/xzc/cpp/test# ./libev_hello
./libev_hello: error while loading shared libraries: libev.so.4: 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下的内容:


[email protected]:/usr/local/lib# ls -lh
total 368K
-rw-r--r-- 1 root staff 213K May 10 00:23 libev.a
-rwxr-xr-x 1 root staff 926 May 10 00:23 libev.la
lrwxrwxrwx 1 root staff 14 May 10 00:23 libev.so -> libev.so.4.0.0
lrwxrwxrwx 1 root staff 14 May 10 00:23 libev.so.4 -> libev.so.4.0.0
-rwxr-xr-x 1 root staff 133K May 10 00:23 libev.so.4.0.0
drwxrwsr-x 4 root staff 4.0K Sep 10 2013 python2.6

解决运行的问题,仔细看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库

时间: 2024-10-21 00:30:01

debian下编译libev库的相关文章

在Ubuntu下编译Assimp库

在Ubuntu下编译Assimp库 如何在Ubuntu下编译Assimp库?这是我以前编译成功后做的笔记,供参考. 1.去下面的网站去下载Assimp库: http://assimp.sourceforge.net/ 2.安装cmake,似乎Assimp库只能通过cmake和vs工程文件进行构建,普通的makfile是通过它来产生的.Ubuntu下使用sudo apt-get install cmake.然后通过cmake --version查看cmake的版本,我cmake版本是2.8.11.

win下编译ffmpeg库,Compile and build ffmpeg library and dll on Windows x64( 正版)

转载请注明:来自EricKing,thanks 从没想到编一个library这么坑爹,再次提醒各位百度的东西只能参考,想节约时间还是要到官网上去查看docum.不废话了,开始详细过程: ——>1.搭建Win下的GCC编译环境(因为win下vs不支持ffmpeg的compile 和build,官网上也有说这一点) ——>2.下载latest ffmpeg source(后面附官网地址),想办法将编译后的文件做成dll,这是win下编程调试的核心 (这里就用到vs下的一个vc的bash文件叫vcv

win7下编译boost库总结

很多情况下都会用到boost库,之前可能通过boostpro直接下载编译好的二进制库,不过遗憾的是目前不再可用了. 下面给出手动编译的过程说明,以版本1.44为例进行说明: 第一步,执行bootstrap.bat,将会在同目录下生成bjam.exe.后面的编译将依赖于bjam.exe 注:bjam.exe --show-libraries可以看到可以编译的库的名称,根据需要进行适当的挑选,也可以全部编译,不过会需要较长时间,建议选择编译自已需要的 第二步,开始编译bjam.exe toolset

Debian下编译安装驱动模块

在Linux下,我们常有需要自己来编译安装驱动模块的情况,例如要安装显卡驱动,要安装无线驱动,有的时候某个程序的安装使用与需要安装相应的驱动模块.Debian Linux下的生活本已十分简单,使用apt可以处理一切.单就我们所讨论的驱动安装,一般情况下,源中也会有已编译的相应驱动可用.但是一般来说,驱动模块与所用的内核版本有着较强的依赖关系,如果源中并没有与我们所用的内核版本相匹配的驱动时,就需要我们自己手动来编译安装驱动模块了.在这样的情况,Debian下的驱动模块编译安装工具m-a就有了用武

【转】Android下编译jni库的二种方法(含示例) -- 不错

原文网址:http://blog.sina.com.cn/s/blog_3e3fcadd01011384.html 总结如下:两种方法是:1)使用Android源码中的Make系统2)使用NDK(从NDK r5开始) ---------------------------------源码要求: 如果Android工程的顶层目录为my_android_project_name:1) my_android_project_name/jni/Android.mk文件的示例内容如下(以生成libjni_

Linux下编译boost库

需要把整个PCIE的工程移植到Linux下,当初就是用cmake来管理的工程的.但是命令行之类的还是需要改动.改动还不少,cmake里面很多东西都依赖于windows.包括我用cmake重新管理的工程IMageMagick,相当繁琐,工作量也大. 当然,首先需要在Linux下安装SVN: http://www.cnblogs.com/macula/archive/2012/02/12/2347637.html http://www.blogjava.net/jasmine214--love/ar

Ubuntu/Debian下编译PC版的ffmpeg

1.安装git: 在命令行下执行 sudo apt-get install git-core 2.下载最新版本的ffmpeg: git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg 3.进入ffmpeg目录下,执行 ./configure 这时可能会提示没有yasm,不能编译汇编,则: 可以下载并安装yasm , sudo apt-get install yasm  也可以在执行./configure时加上参数-disable-yasm 直接执行

Linux下编译opencv库[转]

下载源码 从http://sourceforge.net/projects/opencvlibrary 下载OpenCV源码,下载文件为opencv-1.0.0.tar.gz(如果是其他版本,文件名相应改变,建议下载当时最新的版本). [编辑] 解压文件 tar zxvf opencv-1.0.0.tar.gz cd opencv-1.0.0 [编辑] 检查软件配置 $./configure checking build system type... i686-pc-linux-gnu chec

windows(msvc)下编译boost库

下载&解压 从 http://www.boost.org/ 上下载源码并解压 打开 vs 的本机工具命令提示符 cd boost_sourcecode_dir bootstrap 如果需要编译 boost.python 需要在 boost_sourcecode_dir\tools\build\example\user-config.jam 中添加如下内容: using msvc : 14.0 ; using python : 2.7 : F:\\ProgramData\\Anaconda2 :