linux下boost编译安装全过程脚本塈bzip2编译安装全过程脚本
来源:互联网 发布:java的应用领域与方向 编辑:程序博客网 时间:2024/06/11 13:39
boost编译安装
build_boost.sh
#!/bin/bashshell_folder=$(cd "$(dirname "$0")";pwd)pushd $shell_folder# 上一条命令执行出错则中止脚本执行exit_on_error(){ if [ ! $? -eq 0 ] then echo "exit for error" exit -1 fi}# 如果文件/文件夹存在则删除remove_if_exist(){ if [ $# -eq 1 ] then if [ -e $1 ] then rm $1 -fr if [ ! $? -eq 0 ] then exit -1 fi fi return 0 else echo invalid argument: echo $* exit -1 fi}# 清除指定文件夹的内容,如果文件夹不存在则创建空文件夹clearn_folder(){ if [ $# -eq 1 ] then if [ -d "$1" ] then rm -fr $1/* else mkdir -p "$1" fi exit_on_error else echo invalid argument: echo $* exit -1 fi}# 生成安装路径名后缀install_suffix(){ if [ $# -eq 1 ] then typeset -l os processor os=`uname -s` processor=`uname -p` echo $1_${os}_${processor} else echo invalid argument: echo $* exit -1 fi}# 如果文件存在且checksum与$2指定的md5相等则返回 1,否则返回0# $1 待检查的文件路径# $2 md5校验码need_download(){ if [ $# -eq 2 ] then if [ -f $1 ]; then echo "File already exists. Checking md5..." os=`uname -s` if [ "$os" = "Linux" ]; then checksum=`md5sum $1 | awk '{ print $1 }'` elif [ "$os" = "Darwin" ]; then checksum=`cat $1 | md5` fi if [ "$checksum" = "$2" ]; then echo "Checksum is correct. No need to download $1." return 1 else echo "Checksum is incorrect. Need to download again $1" fi else return 0 fi else echo invalid argument: echo $* exit -1 fi}###############下载boostBOOST_VERSION="1.58.0"BOOST_FOLDER="boost_${BOOST_VERSION//./_}"BOOST_PACKAGE="$BOOST_FOLDER.tar.gz"# 注意这里的md5是1.58.0版本tar.gz包的md5校验码,如果下载其他版本则该值要重新计算并更新,# 计算md5方法参见need_download函数if need_download $BOOST_PACKAGE "5a5d5614d9a07672e1ab2a250b5defc5"then echo "(下载源码)downloading boost $BOOST_VERSION source" wget --no-check-certificate https://nchc.dl.sourceforge.net/project/boost/boost/$BOOST_VERSION/$BOOST_PACKAGE exit_on_errorfiremove_if_exist $BOOST_FOLDERtar zxvf $BOOST_PACKAGEexit_on_error###################编译boost#安装路径install_folder=$(dirname $(readlink -f $0))/release/$(install_suffix boost)echo install_folder:$install_folderbzip2_path=$(dirname $(readlink -f $0))/release/$(install_suffix bzip2)pushd boost_1_58_0# 指定bzip2位置,编译iostreams库时需要# 如果不指定编译iostreams时会报错找不到:bzlib.hexport LIBRARY_PATH=$bzip2_path/lib:$LIBRARY_PATHexport CPLUS_INCLUDE_PATH=$bzip2_path/include:$CPLUS_INCLUDE_PATH# 不编译python库./bootstrap.sh --without-libraries=pythonexit_on_error./b2 --clean# 删除原安装路径remove_if_exist $INSTALL_FOLDER# --prefix 指定安装位置# --debug-configuration 编译时显示加载的配置信息# -q 参数指示出错就停止编译# link=static 只编译静态库./b2 --prefix=$INSTALL_FOLDER -q --debug-configuration link=static installpopd
以上脚本完成boost源码下载编译安装全过程,注意,如果没有安装bzip2,则在编译过程中会报错
libs/iostreams/src/bzip2.cpp:20:56: fatal error: bzlib.h: No such file or directory
解决这个问题有很简单的办法,就是apt安装libbz2-dev
sudo apt-get install libbz2-dev
但因为项目需要,不能使用编译好的二进制代码 ,我得编译安装bzip2,所以先执行下面的脚本再执行 build_boost.sh,boost才能正常编译。
bzip2编译安装
下面的脚本完成bzip2下载编译安装全过程。
build_bzip2.sh
#!/bin/bashshell_folder=$(cd "$(dirname "$0")";pwd)pushd $shell_folder# 上一条命令执行出错则中止脚本执行exit_on_error(){ if [ ! $? -eq 0 ] then echo "exit for error" exit -1 fi}# 如果文件/文件夹存在则删除remove_if_exist(){ if [ $# -eq 1 ] then if [ -e $1 ] then rm $1 -fr if [ ! $? -eq 0 ] then exit -1 fi fi return 0 else echo invalid argument: echo $* exit -1 fi}# 清除指定文件夹的内容,如果文件夹不存在则创建空文件夹clearn_folder(){ if [ $# -eq 1 ] then if [ -d "$1" ] then rm -fr $1/* else mkdir -p "$1" fi exit_on_error else echo invalid argument: echo $* exit -1 fi}# 生成安装路径名后缀install_suffix(){ if [ $# -eq 1 ] then typeset -l os processor os=`uname -s` processor=`uname -p` echo $1_${os}_${processor} else echo invalid argument: echo $* exit -1 fi}# 如果文件存在且checksum与$2指定的md5相等则返回 1,否则返回0# $1 待检查的文件路径# $2 md5校验码need_download(){ if [ $# -eq 2 ] then if [ -f $1 ]; then echo "File already exists. Checking md5..." os=`uname -s` if [ "$os" = "Linux" ]; then checksum=`md5sum $1 | awk '{ print $1 }'` elif [ "$os" = "Darwin" ]; then checksum=`cat $1 | md5` fi if [ "$checksum" = "$2" ]; then echo "Checksum is correct. No need to download $1." return 1 else echo "Checksum is incorrect. Need to download again $1" fi else return 0 fi else echo invalid argument: echo $* exit -1 fi}###############下载bzip2BZIP2_VERSION="1.0.6"BZIP2_FOLDER="bzip2-$BZIP2_VERSION"BZIP2_PACKAGE="$BZIP2_FOLDER.tar.gz"if need_download $BZIP2_PACKAGE "00b516f4704d4a7cb50a1d97e6e8e15b"then echo "(下载源码)downloading bzip2 $BZIP2_VERSION source" wget --no-check-certificate http://www.bzip.org/$BZIP2_VERSION/$BZIP2_PACKAGE exit_on_errorfiremove_if_exist $BZIP2_FOLDERtar zxvf $BZIP2_PACKAGEexit_on_errorbzip2_makefile=$BZIP2_FOLDER/Makefile# 使用sed编译器修改Makefile,在编译选项中增加-fPIC参数# 判断CFLAGS中是否已经有-fPIC选项,如果没有就添加,没有则不修改if [ -z "$(grep '^\s*CFLAGS\s*=' $bzip2_makefile | grep '\-fPIC')" ] then echo "add -fPIC to CFLAGS in $bzip2_makefile" sed -i -r 's/(^\s*CFLAGS\s*=)(.*$)/\1-fPIC \2/' $bzip2_makefile exit_on_errorelse echo "found -fPIC in CFLAGS,no need modify $bzip2_makefile"fi###################编译bzip2#安装路径install_folder=$(dirname $(readlink -f $0))/release/$(install_suffix bzip2)echo install_folder:$install_folderpushd bzip2-1.0.6clearn_folder $install_foldermake cleanexit_on_errormake -j8make install PREFIX=$install_folder exit_on_errorpopd
另外,在编译bzip2之前,要修改bzip2的Makefile.在CFLAGS定义中增加-fPIC
选项,如下:
CFLAGS=-fPIC -Wall -Winline -O2 -g $(BIGFILES)
否则编译boost时会报错,在下载bzip2源码的脚本中有相关的代码用于自动在CFLAGS定义中增加-fPIC
选项
上面两个脚本中有不少相同的函数,为方便维护,在实际工程中,我是把它合并放在一个库文件中的,本文为了让每个脚本都能独立运行,才特别将公用函数分别复制到每个脚本中。
阅读全文
0 0
- linux下boost编译安装全过程脚本塈bzip2编译安装全过程脚本
- linux下protobuf 下载并cmake编译安装全过程脚本
- 在suse linux 下 使用脚本安装 sybase 全过程
- Linux 下编译并安装配置 Qt 全过程
- Linux 下编译并安装配置 Qt 全过程
- 在Linux环境下编译安装配置PostGIS/PostgreSQL全过程
- Linux 下编译并安装配置 Qt 全过程
- Linux 下编译并安装配置 Qt 全过程
- Linux 下编译并安装配置 Qt 全过程
- Linux 下编译并安装配置 Qt 全过程
- Linux 下编译并安装配置 Qt 全过程
- linux 下 android编译全过程
- Linux下boost编译安装
- Linux下编译安装BOOST
- Linux下编译安装boost
- Linux下Boost编译安装
- qt4:windows下安装qt4及编译mysql5驱动程序全过程
- Ubuntu下Snort从编译、安装到调试全过程
- 复制AItsuki的Android:SwipeRefreshLayout和ViewPager滑动冲突的原因和正确的解决方式
- [C++]copy constructor and copy assignment operator
- vueJS搭建环境时 安装npm镜像出错解决方案
- Deep Learning的学习实践 1 -- 基础介绍
- Environment类的方法与常量
- linux下boost编译安装全过程脚本塈bzip2编译安装全过程脚本
- 【mysql的设计与优化专题】表的垂直拆分和水平拆分
- MySQL 调优/优化的 100 个建议
- 子网掩码
- 如何杀掉(kill)Oracle中的会话(Session)
- oracle自动获取sql执行计划
- 一辆智能小车
- css 常用属性
- SSH连接及端口转发