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.必要软件 ...
随机推荐
- [Unity3D][Vuforia][IOS]vuforia在unity3d中添加自己的动态模型,识别自己的图片,添加GUI,播放视频
使用环境 unity3D 5 pro vuforia 4 ios 8.1(6.1) xcode 6.1(6.2) 1.新建unity3d工程,添加vuforia 4.0的工程包 Hierarchy中 ...
- 单利 复利计算器程序1.0 2.0 3.0 [ 合 ] 之 C语言
本程序用C语言编写~~~ 1.计算:本金为100万,利率或者投资回报率为3%,投资年限为30年,那么,30年后所获得的利息收入:按复利计算公式来计算就是:1,000,000×(1+3%)^30 1 v ...
- R2D2 and Droid Army(多棵线段树)
R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Shuffle'm Up 分类: 函数 POJ 查找 2015-08-09 17:01 6人阅读 评论(0) 收藏
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7529 Accepted: 3466 Descript ...
- gulp 建立一个简单的自动化
前端项目需要的功能: 1.图片(压缩图片支持jpg.png.gif) 2.样式 (支持sass 同时支持合并.压缩.重命名) 3.javascript (检查.合并.压缩.重命名) 4.html (压 ...
- 2016年10月29日 星期六 --出埃及记 Exodus 19:14
2016年10月29日 星期六 --出埃及记 Exodus 19:14 After Moses had gone down the mountain to the people, he consecr ...
- eclipse 智能提示
eclipse 智能提示 1.显示行号 2.android 的xml提示 文本框的内容为: <=:.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU ...
- VC 实现文件与应用程序关联(转载)
转载:http://www.cnblogs.com/RascallySnake/archive/2013/03/01/2939102.html 日常工作中,doc文件直接双击后,就能启动word软件, ...
- GetLastInputInfo计时用户离开电脑及软件在指定时间锁定等(转)
/************************************************************************/ /* 说明: 调用函数GetLastInputIn ...
- 用InstallShield 打包工具 打 Win32 程序 (depends.exe 用看程序都依赖了哪些dll)
InstallShield 打包工具 1. 转载:http://blog.csdn.net/zhang_xinxiu/article/details/9099757 2. 转载:http://www. ...