提示:文章
文章目录
前言
前期疑问:
本文目标:
一、 背景
今天把libtiff编译一下看看。在stxdio_wrapper仓库中,这个组件是将静态库文件上传到仓库的,上次会议的时候还在考虑是不是因为有什么坑,然后这个组件是没有比阿尼已脚本的,所以自己也想试着写一下编译脚本。就开始了libtiff编译
二、编译过程
2.1 代码仓地址
https://github.com/Hexagon-HTC/libtiff/tags
2.2 编写脚本
#!/bin/bash
set -ex
#等于是把pwd的路径赋值给PREFIX_INC_PATH变量
PREFIX_INC_PATH=$(cd "$(dirname "$0")";pwd)
echo "${PREFIX_INC_PATH}"
chmod -777 LibTIFF_-_TIFF_Library_and_Utilities-v4.6.0
cd LibTIFF_-_TIFF_Library_and_Utilities-v4.6.0
ls
./autogen.sh
#--prefix=是指定安装路径
./configure --prefix=${PREFIX_INC_PATH}/libLiff
make -j8
#make install才是安装动作
make install
上述的shell文件其实也是包含了平时自己疑惑的几个知识点,正好顺便整理了一遍。当然shell脚本涉及的知识点比较多,但是就是慢慢来嘛
之前自己在脚本里调试的时候经常还拎不清如果需要打印文件夹文件信息,到底是要用ll还是ls。上述的脚本也体现出来了。
这个组件的源码全量编译的,源码中没有configure文件,所以使用autoconf文件编译。因为之前我使用过autoconf,就直接写了autoconf,但是根据打印信息(因为写了set -ex),看到打印信息是autoconf找不到。
#!/bin/bash
set -ex
PREFIX_INC_PATH=$(cd "$(dirname "$0")";pwd)
echo "${PREFIX_INC_PATH}"
chmod -777 LibTIFF_-_TIFF_Library_and_Utilities-v4.6.0
cd LibTIFF_-_TIFF_Library_and_Utilities-v4.6.0
ls
autogen.sh
会报错如下:
+ autogen.sh
build2.sh: 15: build2.sh: autogen.sh: not found
写成可以正常执行
./autogen.sh
2.3 执行脚本
按照脚本编译,可以正常编译libtiff组件。安装路径就是编译脚本指定的路径。make install语句执行完就安装在路径中。
./configure --prefix=${PREFIX_INC_PATH}/libLiff
同样的,安装过程中,打印出对应语句
----------------------------------------------------------------------
Libraries have been installed in:
/root/gdal_0407/libtiff/libLiff/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.
----------------------------------------------------------------------
以我目前的理解,就是make intall是将libtiff安装在了${PREFIX_INC_PATH}/libLiff文件夹中,并没有安装在系统路径,所以需要用
export LD_LIBRARY_PATH=${PREFIX_INC_PATH}/libgeos/lib:$LD_LIBRARY_PATH
指定系统搜索路径。
至于这样的理解是否是完全对的,这边不深究。
安装过程中我也理解了为什么会将libtiff静态库文件上传到代码仓中,因为libtiff在安装过程中会在外网下载文件,在流水线中肯定是下载不到这些文件,所以这是为什么上传libtiff静态库文件的原因。可以从autoconf.sh文件中看出
#!/bin/sh
set -x
case `uname` in
Darwin*)
glibtoolize --force --copy
;;
*)
libtoolize --force --copy
;;
esac
aclocal -I ./m4
autoheader
automake --foreign --add-missing --copy
autoconf
# Get latest config.guess and config.sub from upstream master since
# these are often out of date.
for file in config.guess config.sub
do
echo "$0: getting $file..."
wget -q --timeout=5 -O config/$file.tmp \
"https://git.savannah.gnu.org/cgit/config.git/plain/${file}" \
&& mv -f config/$file.tmp config/$file \
&& chmod a+x config/$file
retval=$?
rm -f config/$file.tmp
test $retval -eq 0 || exit $retval
done
三、总结
现在对于第三方组件编译有了进一步的理解。结合上次写的使用autotool工具自动生成makefile文件的帖子。算是有了多一些的理解吧。
总结
未完待续