Rocky Linux 9 编译安装 libgd

By | 最新修改:2024-08-17

GD 全称 “GD Graphics (Draw) Library”(GD 图形(绘图)库),可以让程序员动态地创建图形图像。

本文的主要内容是:在 Rocky Linux 9 系统下通过源代码进行编译安装 GD 库。

由于在部署 LNMP 架构时业务功能的需求,在 Nginx 编译源代码时需要 GD 库的支持。

libgd-gd库

前提条件

本次从源代码编译安装的 LibGD 要支持 WebP 功能,因此在编译 LibGD 之前要先编译安装 libwebp 库。

具体请见: Rocky Linux 9 编译安装 libWebP 库


安装依赖

dnf install -y git wget autoconf automake libtool freetype-devel fontconfig \
libpng-devel libtiff-devel freetype-devel fontconfig-devel \
libpng giflib libtiff

下载 libgd 的源代码

如果因为网络问题不能下载源码包,那么请参考本站的其他文章: 如何在境内加速 GitHub 资源的下载以及克隆

cd /tmp
# 如果不存在,则创建它
## git clone https://github.com/libgd/libgd.git
# 获取最新版本: https://github.com/libgd/libgd/releases/
LIBGD_VER=2.3.3
if [ ! -f libgd-${LIBGD_VER}.tar.gz ]; then
    echo "+++++++++++++++++++++++++++++++++Downloading LibGD source code."
    wget https://github.com/libgd/libgd/releases/download/gd-${LIBGD_VER}/libgd-${LIBGD_VER}.tar.gz
    code=$?

    while [ $code -gt 0 ]; do
        rm -f libgd-${LIBGD_VER}.tar.gz*
        echo "+++++++++++++++++++++++++++++++++Again downloading LibGD source code."
        wget https://github.com/libgd/libgd/releases/download/gd-${LIBGD_VER}/libgd-${LIBGD_VER}.tar.gz
        code=$?
    done

    if [ $code -eq 0 ]; then
        echo "+++++++++++++++++++++++++++++++++LibGD file completed done."
    else
        echo "+++++++++++++++++++++++++++++++++LibGD file downloaded failed."
        exit
    fi
fi

if [ -f libgd-${LIBGD_VER}.tar.gz ]; then
    echo "+++++++++++++++++++++++++++++++++Uncompressing libgd source code."
    tar zxvf libgd-${LIBGD_VER}.tar.gz
fi

从源代码编译安装

cd /tmp
if [ -d libgd-${LIBGD_VER} ]; then
    cd libgd-${LIBGD_VER}

    echo "+++++++++++++++++++++++++++++++++Bootstrap LibGD source code:"

    ./bootstrap.sh

    if [ $? -gt 0 ]; then
        echo "+++++++++++++++++++++++++++++++++Failed to bootstrap LibGD source code:"
        exit
    fi

    echo "+++++++++++++++++++++++++++++++++Configuring for libGD compilation."
    ./configure --with-webp --with-jpeg --with-png --with-tiff --enable-shared

    if [ $? -gt 0 ]; then
        echo "+++++++++++++++++++++++++++++++++Failed to configure libGD!"
        exit
    fi

    echo "+++++++++++++++++++++++++++++++++Beginning compile libgd."
    make

    if [ $? -gt 0 ]; then
        echo "+++++++++++++++++++++++++++++++++Failed to compile libgd."
        exit
    fi

    echo "+++++++++++++++++++++++++++++++++Installing libgd."
    make install

    ln -sf /usr/local/lib/libgd.so* /usr/lib64/
    echo "+++++++++++++++++++++++++++++++++Complete libgd installation."
fi

创建 LibGD 动态库的软链接

ln -sf /usr/local/lib/libgd.so* /usr/lib64/

校验动态文件信息

readelf -d /usr/local/lib/libgd.so  /usr/lib64/libgd.so.3

命令执行结果的前面几行信息完全匹配,就表示 LibGD 安装成功。



程序知路

鉴于本人的相关知识储备以及能力有限,本博客的观点和描述如有错漏或是有考虑不周到的地方还请多多包涵,欢迎互相探讨,一起学习,共同进步。

本文章可以转载,但是需要说明来源出处!

本文使用的部分图片来源于网上,若是侵权,请与本文作者联系删除: admin@icxzl.com