这个。。那个。。后来发现。。直接用jumbo就可以安装libevent。不过,学习一些automake的知识还是有好处的。

03机器也安装了。

这几天在阅读libevent源码,发现参考资料是基于libevent-2.1的版本,所以就去官网下载了2.1的版本:

http://libevent.org/ (其实是在git下载的:https://github.com/libevent/libevent),版本应该是libevent-2.1.so.5.0.0

下载下来,发现目录里面没有常见的configure, Makefile等文件,搜索之后,了解到需要使用autoconf, automake等工具进行处理。

首先针对automake等工具进行了学习(目录在/home/work/my_name/autoMake/):

先写了些示例代码,分为两个文件:

helloworld.cpp

#include "helloworld.h"

using namespace std;

int main(int argc, char **argv) {
printf("Hello Linux!\n");
return ;
}

以及helloworld.h

#include <iostream>

autoconf需要configure.ac文件,可以使用autoscan命令先生成configure.scan(错误信息可以先忽略)

[autoMake]$ autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status:
[autoMake]$ ll
-rw-rw-r-- work work May : autoscan.log
-rw-rw-r-- work work May : configure.scan
-rw-rw-r-- work work May : helloworld.cpp
-rw-rw-r-- work work May : helloworld.h

configure.scan原始内容如下:

# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([helloworld.cpp])
AC_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
AC_OUTPUT

将configure.scan改名为configure.in(configure.ac亦可),将内容修改如下:

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script. AC_PREREQ(2.59)
#AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
#modified, ignore 3rd parameter email_address
AC_INIT(helloworld, 1.0)
AC_CONFIG_SRCDIR([helloworld.cpp])
#AC_CONFIG_HEADER([config.h])
#added
AM_INIT_AUTOMAKE(helloworld, 1.0) # Checks for programs.
AC_PROG_CXX # Checks for libraries. # Checks for header files. # Checks for typedefs, structures, and compiler characteristics. # Checks for library functions. #added
AC_CONFIG_FILES([Makefile]) AC_OUTPUT

直接运行autoconf,会有如下报错(但是configure文件仍然生成)

[autoMake]$ autoconf
configure.in:: error: possibly undefined macro: AM_INIT_AUTOMAKE
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
[utoMake]$ ll
total
drwxr-xr-x work work May : autom4te.cache
-rw-rw-r-- work work May : autoscan.log
-rwxrwxr-x work work May : configure
-rw-rw-r-- work work May : configure.in
-rw-rw-r-- work work May : helloworld.cpp
-rw-rw-r-- work work May : helloworld.h

这个报错是因为没有运行命令aclocal来生成宏(会生成文件aclocal.m4)。删除刚刚生成的文件,重新运行如下:

[autoMake]$ aclocal
[autoMake]$ autoconf
[autoMake]$ ll
total
-rw-rw-r-- work work May : aclocal.m4
drwxr-xr-x work work May : autom4te.cache
-rw-rw-r-- work work May : autoscan.log
-rwxrwxr-x work work May : configure
-rw-rw-r-- work work May : configure.in
-rw-rw-r-- work work May : helloworld.cpp
-rw-rw-r-- work work May : helloworld.h

在下一步automake前,需要新建文件Makefile.am,内容如下:

AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=helloworld
helloworld_SOURCES=helloworld.cpp helloworld.h

automake提供了三种软件等级:foreign、gnu和gnits,这里选择foreign,就会只检查必须文件。

再之后运行命令:automake --add-missing(选项--add-missing的定义是“add missing standard files to package”,它会让automake加入一个标准的软件包所必须的一些文件。)

[autoMake]$ automake --add-missing
configure.in: installing `./install-sh'
configure.in: installing `./missing'
Makefile.am: installing `./depcomp'
[autoMake]$ ll
total
-rw-rw-r-- work work May : aclocal.m4
drwxr-xr-x work work May : autom4te.cache
-rw-rw-r-- work work May : autoscan.log
-rwxrwxr-x work work May : configure
-rw-rw-r-- work work May : configure.in
lrwxrwxrwx work work May : depcomp -> /usr/share/automake-1.9/depcomp
-rw-rw-r-- work work May : helloworld.cpp
-rw-rw-r-- work work May : helloworld.h
lrwxrwxrwx work work May : install-sh -> /usr/share/automake-1.9/install-sh
-rw-rw-r-- work work May : Makefile.am
-rw-rw-r-- work work May : Makefile.in
lrwxrwxrwx work work May : missing -> /usr/share/automake-1.9/missing

可以发现,Makefile.in文件被生成了。再之后,就可以用configure命令了:

[autoMake]$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for g++... g++
checking for C++ compiler default output file name... a.out
checking whether the C++ compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: error: cannot find input file: config.h.in

可以看到Makefile文件被生成:

[autoMake]$ ll
total
-rw-rw-r-- work work May : aclocal.m4
drwxr-xr-x work work May : autom4te.cache
-rw-rw-r-- work work May : autoscan.log
-rw-rw-r-- work work May : config.log
-rwxrwxr-x work work May : config.status
-rwxrwxr-x work work May : configure
-rw-rw-r-- work work May : configure.in
lrwxrwxrwx work work May : depcomp -> /usr/share/automake-1.9/depcomp
-rw-rw-r-- work work May : helloworld.cpp
-rw-rw-r-- work work May : helloworld.h
lrwxrwxrwx work work May : install-sh -> /usr/share/automake-1.9/install-sh
-rw-rw-r-- work work May : Makefile
-rw-rw-r-- work work May : Makefile.am
-rw-rw-r-- work work May : Makefile.in
lrwxrwxrwx work work May : missing -> /usr/share/automake-1.9/missing

再之后,通过make,就能生成可执行文件:

[autoMake]$ make
cd . && /bin/sh /home/work/liu_chao/autoMake/missing --run aclocal-1.9
cd . && /bin/sh /home/work/liu_chao/autoMake/missing --run automake-1.9 --foreign
cd . && /bin/sh /home/work/liu_chao/autoMake/missing --run autoconf
/bin/sh ./config.status --recheck
running /bin/sh ./configure --no-create --no-recursion
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for g++... g++
checking for C++ compiler default output file name... a.out
checking whether the C++ compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
configure: creating ./config.status
/bin/sh ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
if g++ -DPACKAGE_NAME=\"helloworld\" -DPACKAGE_TARNAME=\"helloworld\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"helloworld\ 1.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"helloworld\" -DVERSION=\"1.0\" -I. -I. -g -O2 -MT helloworld.o -MD -MP -MF ".deps/helloworld.Tpo" -c -o helloworld.o helloworld.cpp; \
then mv -f ".deps/helloworld.Tpo" ".deps/helloworld.Po"; else rm -f ".deps/helloworld.Tpo"; exit ; fi
g++ -g -O2 -o helloworld helloworld.o
[autoMake]$ ll
total
-rw-rw-r-- work work May : aclocal.m4
drwxr-xr-x work work May : autom4te.cache
-rw-rw-r-- work work May : autoscan.log
-rw-rw-r-- work work May : config.log
-rwxrwxr-x work work May : config.status
-rwxrwxr-x work work May : configure
-rw-rw-r-- work work May : configure.in
lrwxrwxrwx work work May : depcomp -> /usr/share/automake-1.9/depcomp
-rwxrwxr-x work work May : helloworld
-rw-rw-r-- work work May : helloworld.cpp
-rw-rw-r-- work work May : helloworld.h
-rw-rw-r-- work work May : helloworld.o
lrwxrwxrwx work work May : install-sh -> /usr/share/automake-1.9/install-sh
-rw-rw-r-- work work May : Makefile
-rw-rw-r-- work work May : Makefile.am
-rw-rw-r-- work work May : Makefile.in
lrwxrwxrwx work work May : missing -> /usr/share/automake-1.9/missing

make install是将可执行文件安装到系统目录中。这里不需要这一步。

可以通过make dist来生成安装包:

[autoMake]$ make dist
{ test ! -d helloworld-1.0 || { find helloworld-1.0 -type d ! -perm - -exec chmod u+w {} ';' && rm -fr helloworld-1.0; }; }
mkdir helloworld-1.0
find helloworld-1.0 -type d ! -perm - -exec chmod a+rwx {} \; -o \
! -type d ! -perm - -links -exec chmod a+r {} \; -o \
! -type d ! -perm - -exec chmod a+r {} \; -o \
! -type d ! -perm - -exec /bin/sh /home/work/liu_chao/autoMake/install-sh -c -m a+r {} {} \; \
|| chmod -R a+r helloworld-1.0
tardir=helloworld-1.0 && /bin/sh /home/work/liu_chao/autoMake/missing --run tar chof - "$tardir" | GZIP=--best gzip -c >helloworld-1.0.tar.gz
{ test ! -d helloworld-1.0 || { find helloworld-1.0 -type d ! -perm - -exec chmod u+w {} ';' && rm -fr helloworld-1.0; }; }
[autoMake]$ ll
total
-rw-rw-r-- work work May : aclocal.m4
drwxr-xr-x work work May : autom4te.cache
-rw-rw-r-- work work May : autoscan.log
-rw-rw-r-- work work May : config.log
-rwxrwxr-x work work May : config.status
-rwxrwxr-x work work May : configure
-rw-rw-r-- work work May : configure.in
lrwxrwxrwx work work May : depcomp -> /usr/share/automake-1.9/depcomp
-rwxrwxr-x work work May : helloworld
-rw-rw-r-- work work May : helloworld-1.0.tar.gz
-rw-rw-r-- work work May : helloworld.cpp
-rw-rw-r-- work work May : helloworld.h
-rw-rw-r-- work work May : helloworld.o
lrwxrwxrwx work work May : install-sh -> /usr/share/automake-1.9/install-sh
-rw-rw-r-- work work May : Makefile
-rw-rw-r-- work work May : Makefile.am
-rw-rw-r-- work work May : Makefile.in
lrwxrwxrwx work work May : missing -> /usr/share/automake-1.9/missing

可以看到,生成了 helloworld-1.0.tar.gz 这个文件。

到此,autoconf, automake, configure,和make等常用软件编译和安装的方式已经总结完成。

————————

下面进行libevent的编译,使用命令:

aclocal

autoconf

autoheader

automake --add-missing

出现

configure.ac:125: required file `./ltmain.sh' not found

搜索之后,使用:

libevent-master]$ libtoolize --version
libtoolize (GNU libtool) 1.5.6

Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
libevent-master]$ libtoolize --automake --copy --debug --force

然后重新输入命令:

automake --add-missing

发现没有ltmain.sh相关的错误,但是返回码仍然是1,并且无Makefile生成。

——————————————

重新阅读目录自带的README.md,发现:

# 1. BUILDING AND INSTALLATION (In Depth)

## Autoconf

To build libevent, type

$ ./configure && make

(If you got libevent from the git repository, you will
first need to run the included "autogen.sh" script in order to
generate the configure script.)

所以运行autogen.sh命令:

libevent-master]$ sh autogen.sh
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: running: libtoolize --copy --force
autoreconf: running: /usr/bin/autoconf --force
autoreconf: running: /usr/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
autoreconf: Leaving directory `.'

最后返回码为0,并且成功生成Makefile.in(最终的Makefile需要通过 ./configure来生成)

再之后就是下面的命令:

./configure (注意,2.1的libevent默认安装在/usr/local/lib里,需要--prefix=/usr让这个库安装到/usr/lib)

make

make install(可能需要root权限)

——————————————————

关于安装目录,查到的资料是,加载动态库的顺序是:

1. 编译的时候加上-Wl,-rpath=目录的选项,就会在目录程序的.dynamic 段包含一个叫DT_RPATH的项,里面有冒号分隔的目录。

2. 先根据LD_LIBRARY_PATH

3. 再看/etc/ld.so.conf

4. 最后依次在 /lib /usr/lib里查找

开始的时候,我没有注意看编译定义的文件,后来看到的确把/usr/local目录包含了进去,看来使用默认目录/usr/local应该也没有问题。

编译的命令可以参考:

g++ -o lserver lserver.cpp -I/usr/local/include -levent -L/usr/local/lib -Wl,-rpath=/usr/local/lib

libevent源码安装及Linux自动编译功能总结的更多相关文章

  1. CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)环境【转载】

    本文转载自 园友David_Tang的博客,如有侵权请联系本人及时删除,原文地址: http://www.cnblogs.com/mchina/archive/2012/11/28/2778779.h ...

  2. memcached源码安装(linux和windows)

    如果是在windows环境下编译安装,我这边是基于cygwin或msys2方式 安装cygwin环境,http://www.cnblogs.com/skey_chen/p/5765179.html 安 ...

  3. CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)环境

    一.简介 什么是LAMP    LAMP是一种Web网络应用和开发环境,是Linux, Apache, MySQL, Php/Perl的缩写,每一个字母代表了一个组件,每个组件就其本身而言都是在它所代 ...

  4. CentOS 6.3 源码安装LAMP(Linux+Apache+Mysql+Php)环境

    一.简介 什么是LAMP LAMP是一种Web网络应用和开发环境,是Linux, Apache, MySQL, Php/Perl的缩写,每一个字母代表了一个组件,每个组件就其本身而>言都是在它所 ...

  5. CentOS 6.5下源码安装LAMP(Linux+Apache+Mysql+Php)环境

    ---恢复内容开始--- 一.系统环境 系统平台:CentOS 6.5 (Final) Apache版本:httpd-2.2.31.tar.gz(最新版本2015-07-16) Mysql 版本:my ...

  6. Mysql依赖库Boost的源码安装,linux下boost库的安装

      boost‘准标准库’安装过程.安装的是boost_1_60_0. (1)首先去下载最新的boost代码包,网址www.boost.org. (2)进入到自己的目录,解压: bzip2 -d bo ...

  7. Linux中源码安装编译Vim

    Linux中源码安装编译Vim Linux下学习工作少不了编辑器,Vim能使你的工作效率成倍的提高.在Ubuntu上安装vim使用命令直接安装很简单.但有时还是需要自己手动编译安装.例如: vim中的 ...

  8. 【程序包管理】Linux软件管理之src源码安装编译

    在很多时候我们需要自定义软件的特性,这时就需要用到源码安装.那么,网上有很多编译源码的工具,那么,我们怎么知道别人使用的是什么工具呢.其实我也不知道(*^▽^*). 那么本篇博客主要是写C代码的源码安 ...

  9. linux下MySQL 5.6源码安装

    linux下MySQL 5.6源码安装 1.下载:当前mysql版本到了5.6.20 http://dev.mysql.com/downloads/mysql 选择Source Code 2.必要软件 ...

随机推荐

  1. Android Studio解决unspecified on project app resolves to an APK archive which is not supported

    出现该问题unspecified on project app resolves to an APK archive which is not supported as a compilation d ...

  2. (摘至)程序员老鸟写sql语句的经验之谈

    做管理系统的,无论是bs结构的还是cs结构的,都不可避免的涉及到数据库表结构的设计,sql语句的编写等.因此在开发系统的时候,表结构设计是否合理,sql语句是否标准,写出的sql性能是否优化往往会成为 ...

  3. c#之线程池

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  4. Poj(1469),二分图最大匹配

    题目链接:http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

  5. ie兼容整理

    那里面有东西要长研究 ie bug集合关于如何给各种浏览器打bug,可查询:browser hacks 几篇处理ie问题的帖子,帖子1

  6. sql通用分页自定义表条件存储过程

    create PROCEDURE PrcTestByPage ( @tablename varchar(50), @selectfilter varchar(100), @orderbyfilter ...

  7. java中为什么byte的取值范围是-128到+127

    概念:java中用补码表示二进制数,补码的最高位是符号位,最高位为“0”表示正数,最高位为“1”表示负数.正数补码为其本身:负数补码为其绝对值各位取反加1:例如:+21,其二进制表示形式是000101 ...

  8. xtrabackup 安装、备份、还原及错误处理 教程

    xtrabackup 是MYSQL的一个备份软件 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个 ...

  9. ZOJ 1015 Fishing Net(判断弦图)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=15 题意:给定一个图.判断是不是弦图? 思路:(1)神马是弦图?对于一 ...

  10. js表单操作

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...