libevent源码安装及Linux自动编译功能总结
这个。。那个。。后来发现。。直接用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自动编译功能总结的更多相关文章
- CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)环境【转载】
本文转载自 园友David_Tang的博客,如有侵权请联系本人及时删除,原文地址: http://www.cnblogs.com/mchina/archive/2012/11/28/2778779.h ...
- memcached源码安装(linux和windows)
如果是在windows环境下编译安装,我这边是基于cygwin或msys2方式 安装cygwin环境,http://www.cnblogs.com/skey_chen/p/5765179.html 安 ...
- CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)环境
一.简介 什么是LAMP LAMP是一种Web网络应用和开发环境,是Linux, Apache, MySQL, Php/Perl的缩写,每一个字母代表了一个组件,每个组件就其本身而言都是在它所代 ...
- CentOS 6.3 源码安装LAMP(Linux+Apache+Mysql+Php)环境
一.简介 什么是LAMP LAMP是一种Web网络应用和开发环境,是Linux, Apache, MySQL, Php/Perl的缩写,每一个字母代表了一个组件,每个组件就其本身而>言都是在它所 ...
- CentOS 6.5下源码安装LAMP(Linux+Apache+Mysql+Php)环境
---恢复内容开始--- 一.系统环境 系统平台:CentOS 6.5 (Final) Apache版本:httpd-2.2.31.tar.gz(最新版本2015-07-16) Mysql 版本:my ...
- Mysql依赖库Boost的源码安装,linux下boost库的安装
boost‘准标准库’安装过程.安装的是boost_1_60_0. (1)首先去下载最新的boost代码包,网址www.boost.org. (2)进入到自己的目录,解压: bzip2 -d bo ...
- Linux中源码安装编译Vim
Linux中源码安装编译Vim Linux下学习工作少不了编辑器,Vim能使你的工作效率成倍的提高.在Ubuntu上安装vim使用命令直接安装很简单.但有时还是需要自己手动编译安装.例如: vim中的 ...
- 【程序包管理】Linux软件管理之src源码安装编译
在很多时候我们需要自定义软件的特性,这时就需要用到源码安装.那么,网上有很多编译源码的工具,那么,我们怎么知道别人使用的是什么工具呢.其实我也不知道(*^▽^*). 那么本篇博客主要是写C代码的源码安 ...
- linux下MySQL 5.6源码安装
linux下MySQL 5.6源码安装 1.下载:当前mysql版本到了5.6.20 http://dev.mysql.com/downloads/mysql 选择Source Code 2.必要软件 ...
随机推荐
- 网络统计学与web前端开发基础技术
网络统计学与web前端开发基础技术 学习web前端开发基础技术(网页设计)需要了解:HTML.CSS.JavaScript三种语言.下面我们就来了解一下这三门技术在网页设计中的用途: HTML是网页内 ...
- getElementByClassName()不兼容的解决办法
在获取元素时候采用getElementByClassName()方法是比较方便的,但是对于IE6不兼容,可以采用以下代码来自定义这个方法: window.onload=function(){ if(! ...
- 八大排序算法之五--交换排序—冒泡排序(Bubble Sort)
基本思想: 在要排序的一组数中,对当前还未排好序的范围内的全部数,自上而下对相邻的两个数依次进行比较和调整,让较大的数往下沉,较小的往上冒.即:每当两相邻的数比较后发现它们的排序与排序要求相反时,就将 ...
- jquery 实现页面局部刷新ajax做法
这个方法就多了去了,常见的有以下几种:下面介绍全页面刷新方法:有时候可能会用到 window.location.reload()刷新当前页面. parent.location.reload()刷新父亲 ...
- office软件
32位系统office2013: http://pan.baidu.com/s/1bnCqMZ1 64位系统office2013: http://pan.baidu.com/s/1i33rdHF vi ...
- Unity-Animator深入系列---录制与回放
回到 Animator深入系列总目录 Animator自带了简单的动画录制,回放功能.但可惜的是不支持持久化的数据输出.因而不能作为录像保存 不过这种可以作为竞速,格斗类游戏在结束时经常出现的游戏回放 ...
- Animator角色重复受击播放问题
需要指定开始时间参数,否则Animator会默认当前已经在播放这个动画而忽略掉 CrossFade一样 gif: public class AnimatorDebug : MonoBehaviour ...
- hiho一下,第115周,FF,EK,DINIC
题目1 : 网络流一·Ford-Fulkerson算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho住在P市,P市是一个很大很大的城市,所以也面临着一个 ...
- Poj(1511),SPFA
题目链接:http://poj.org/problem?id=1511 嗯,最后一次写SPFA了,以后就套模板了. 题意:给出n个点和n条有向边,求所有点到源点1的来回最短路之和(保证每个点都可以往返 ...
- XML 增删改查
<?php $xmlpatch = 'index.xml'; $_id = '; $_title = 'title1'; $_content = 'content1'; $_author = ' ...