2

我正在尝试在 Oracle Linux Server 7.1 版中创建 pngquant 的静态链接版本。我已经编译了 zlib 的静态版本和 libpng 的静态版本。

然后,当我配置 pngquant 时,我总是得到它会与 zlib 的共享版本链接的信息。

$ ./configure --with-libpng=../libpng-1.6.21 --extra-cflags="-I../zlib-1.2.8" --extra-ldflags="../zlib-1.2. 8/libz.a"

  编译器:gcc
     调试:没有
       上证所:是
    OpenMP:没有
    libpng:静态(1.6.21)
      zlib:共享(1.2.7)
     lcms2:没有

如果我执行 make,在输出中似乎选项已正确传递给编译器。但是,生成的二进制文件需要执行 libz.so。似乎我的指令被忽略了,或者安装的版本总是优先。

有什么方法可以强制使用 zlib 的静态版本编译 pngquant?

4

2 回答 2

1

我不确定,如果我做对了,但这里有一个对我有用的 pngquant 配置补丁。configure现在接受--with-zlib=<dir>作为参数。将其存储pngquant.patch并使用patch -uN -p1 -i pngquant.patch.

    diff -ur pngquant-2.9.0/configure pngquant-2.9.0.fixed/configure
--- pngquant-2.9.0/configure    2017-03-06 09:37:30.000000000 +0100
+++ pngquant-2.9.0.fixed/configure  2017-03-07 09:57:20.246012152 +0100
@@ -48,6 +48,7 @@
         help "--with-cocoa/--without-cocoa  use Cocoa framework to read images"
 fi
         help "--with-libpng=<dir>           search for libpng in directory"
+        help "--with-zlib=<dir>             search for zlib in directory"
         echo
         help "CC=<compiler>                 use given compiler command"
         help "CFLAGS=<flags>                pass options to the compiler"
@@ -97,6 +98,9 @@
     --with-libpng=*)
         LIBPNG_DIR=${i#*=}
         ;;
+    --with-zlib=*)
+        ZLIB_DIR=${i#*=}
+        ;;
     --prefix=*)
         PREFIX=${i#*=}
         ;;
@@ -238,6 +242,19 @@
     echo "${MAJ}${MIN}"
 }
 
+# returns full zlib.h version string
+zlibh_string() {
+    echo "$(grep -m1 "define ZLIB_VERSION" "$1" | \
+            grep -Eo '"[^"]+"' | grep -Eo '[^"]+')"
+}
+
+# returns major minor version numbers from png.h
+zlibh_majmin() {
+    local MAJ=$(grep -m1 "define ZLIB_VER_MAJOR" "$1" | grep -Eo "[0-9]+")
+    local MIN=$(grep -m1 "define ZLIB_VER_MINOR" "$1" | grep -Eo "[0-9]+")
+    echo "${MAJ}${MIN}"
+}
+
 error() {
     status "$1" "error ... $2"
     echo
@@ -420,11 +437,42 @@
     error "libpng" "not found (try: $LIBPNG_CMD)"
 fi
 
-# zlib
-if ! find_library "zlib" "z" "zlib.h" "libz.a" "libz.$SOLIBSUFFIX*"; then
-    error "zlib" "not found (please install zlib-devel package)"
+# try if given flags are enough for zlib
+HAS_ZLIB=0
+if echo "#include \"zlib.h\"
+    int main(){
+    uLong test = zlibCompileFlags();
+    return 0;
+}" | "$CC" -xc -std=c99 -o /dev/null $CFLAGS $LDFLAGS - &> /dev/null; then
+    status "zlib" "custom flags"
+    HAS_ZLIB=1
 fi
 
+if [ "$HAS_ZLIB" -eq 0 ]; then
+    # try static in the given directory
+    ZLIBH=$(find_h "$ZLIB_DIR" "zlib.h")
+    if [ -n "$ZLIBH" ]; then
+        ZLIBH_STRING=$(zlibh_string "$ZLIBH")
+        ZLIBH_MAJMIN=$(zlibh_majmin "$ZLIBH")
+        if [[ -n "$ZLIBH_STRING" && -n "$ZLIBH_MAJMIN" ]]; then
+            ZLIBA=$(find_f "$ZLIB_DIR" "libz${ZLIBH_MAJMIN}.a")
+            if [ -z "$ZLIBA" ]; then
+                ZLIBA=$(find_f "$ZLIB_DIR" "libz.a")
+            fi
+            if [ -n "$ZLIBA" ]; then
+                cflags "-I${ZLIBH%/*}"
+                lflags "${ZLIBA}"
+                status "zlib" "static (${ZLIBH_STRING})"
+                HAS_ZLIB=1
+            fi
+        fi
+    fi
+fi
+# zlib
+if ! find_library "zlib" "z" "zlib.h" "libz.a" "zlib.$SOLIBSUFFIX*"; then
+    error "zlib" "not found (please install zlib-devel package)"
+fi
+
 # lcms2
 if [ "$LCMS2" != 0 ]; then
     if find_library "lcms2" "lcms2" "lcms2.h" "liblcms2.a" "liblcms2.$SOLIBSUFFIX*"; then
于 2017-03-07T11:44:03.000 回答
0

抱歉,配置脚本不支持。修改 configure 以将适当的标志传递给pkg-config或执行与 libpng 相同的解决方法应该不会太难。

于 2016-04-01T12:05:19.660 回答