mozjpeg icon indicating copy to clipboard operation
mozjpeg copied to clipboard

Cannot build mozjpeg on Alpine Linux

Open tonytonyjan opened this issue 3 years ago • 2 comments

Reproduction

docker run --rm -i alpine:3.14.0 sh <<EOS &> output.txt
set -euo pipefail
apk add cmake make gcc musl-dev curl nasm libpng-dev zlib-dev
cd ~
curl -LSs https://github.com/mozilla/mozjpeg/archive/refs/tags/v4.0.3.tar.gz | tar -xz
mkdir build
cd build
cmake -G"Unix Makefiles" ../mozjpeg-4.0.3
EOS
output.txt
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
(1/35) Installing libacl (2.2.53-r0)
(2/35) Installing libbz2 (1.0.8-r1)
(3/35) Installing expat (2.4.1-r0)
(4/35) Installing lz4-libs (1.9.3-r0)
(5/35) Installing xz-libs (5.2.5-r0)
(6/35) Installing zstd-libs (1.4.9-r1)
(7/35) Installing libarchive (3.5.1-r0)
(8/35) Installing ca-certificates (20191127-r5)
(9/35) Installing brotli-libs (1.0.9-r5)
(10/35) Installing nghttp2-libs (1.43.0-r0)
(11/35) Installing libcurl (7.77.0-r1)
(12/35) Installing ncurses-terminfo-base (6.2_p20210612-r0)
(13/35) Installing ncurses-libs (6.2_p20210612-r0)
(14/35) Installing libgcc (10.3.1_git20210424-r2)
(15/35) Installing rhash-libs (1.4.1-r0)
(16/35) Installing libstdc++ (10.3.1_git20210424-r2)
(17/35) Installing libuv (1.41.0-r0)
(18/35) Installing cmake (3.20.3-r0)
(19/35) Installing curl (7.77.0-r1)
(20/35) Installing binutils (2.35.2-r2)
(21/35) Installing libgomp (10.3.1_git20210424-r2)
(22/35) Installing libatomic (10.3.1_git20210424-r2)
(23/35) Installing libgphobos (10.3.1_git20210424-r2)
(24/35) Installing gmp (6.2.1-r0)
(25/35) Installing isl22 (0.22-r0)
(26/35) Installing mpfr4 (4.1.0-r0)
(27/35) Installing mpc1 (1.2.1-r0)
(28/35) Installing gcc (10.3.1_git20210424-r2)
(29/35) Installing libpng (1.6.37-r1)
(30/35) Installing pkgconf (1.7.4-r0)
(31/35) Installing zlib-dev (1.2.11-r3)
(32/35) Installing libpng-dev (1.6.37-r1)
(33/35) Installing make (4.3-r0)
(34/35) Installing musl-dev (1.2.2-r3)
(35/35) Installing nasm (2.15.05-r0)
Executing busybox-1.33.1-r2.trigger
Executing ca-certificates-20191127-r5.trigger
OK: 185 MiB in 49 packages
-- The C compiler identification is GNU 10.3.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- CMAKE_BUILD_TYPE = Release
-- VERSION = 4.0.3, BUILD = 20210701
-- 64-bit build (x86_64)
-- CMAKE_INSTALL_PREFIX = /opt/mozjpeg
-- CMAKE_INSTALL_BINDIR = bin (/opt/mozjpeg/bin)
-- CMAKE_INSTALL_DATAROOTDIR =  (/opt/mozjpeg)
-- CMAKE_INSTALL_DOCDIR = doc (/opt/mozjpeg/doc)
-- CMAKE_INSTALL_INCLUDEDIR = include (/opt/mozjpeg/include)
-- CMAKE_INSTALL_LIBDIR = lib64 (/opt/mozjpeg/lib64)
-- CMAKE_INSTALL_MANDIR = man (/opt/mozjpeg/man)
-- Shared libraries enabled (ENABLE_SHARED = 1)
-- Static libraries enabled (ENABLE_STATIC = 1)
-- 12-bit JPEG support disabled (WITH_12BIT = 0)
-- Arithmetic decoding support disabled (WITH_ARITH_DEC = 0)
-- Arithmetic encoding support disabled (WITH_ARITH_ENC = 0)
-- TurboJPEG API library enabled (WITH_TURBOJPEG = 1)
-- TurboJPEG Java wrapper disabled (WITH_JAVA = 0)
-- In-memory source/destination managers enabled (WITH_MEM_SRCDST = 1)
-- Emulating libjpeg API/ABI v6.2 (WITH_JPEG7 = 0, WITH_JPEG8 = 0)
-- libjpeg API shared library version = 62.3.0
-- Compiler flags =  -O3 -DNDEBUG
-- Linker flags =  
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of size_t
-- Check size of size_t - done
-- Check size of unsigned long
-- Check size of unsigned long - done
-- Performing Test HAVE_BUILTIN_CTZL
-- Performing Test HAVE_BUILTIN_CTZL - Success
-- Looking for include file locale.h
-- Looking for include file locale.h - found
-- Looking for include file stdlib.h
-- Looking for include file stdlib.h - found
-- Looking for include file sys/types.h
-- Looking for include file sys/types.h - found
-- Looking for memset
-- Looking for memset - found
-- Looking for memcpy
-- Looking for memcpy - found
-- Check size of unsigned char
-- Check size of unsigned char - done
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Performing Test INCOMPLETE_TYPES
-- Performing Test INCOMPLETE_TYPES - Success
-- Compiler supports pointers to undefined structures.
-- Performing Test RIGHT_SHIFT_IS_UNSIGNED
-- Performing Test RIGHT_SHIFT_IS_UNSIGNED - Failed
-- Performing Test __CHAR_UNSIGNED__
-- Performing Test __CHAR_UNSIGNED__ - Failed
-- Performing Test INLINE_WORKS
-- Performing Test INLINE_WORKS - Success
-- INLINE = __inline__ __attribute__((always_inline)) (FORCE_INLINE = 1)
-- Performing Test HAVE_THREAD_LOCAL
-- Performing Test HAVE_THREAD_LOCAL - Success
-- THREAD_LOCAL = __thread
-- Performing Test HAVE_VERSION_SCRIPT
-- Performing Test HAVE_VERSION_SCRIPT - Success
-- Linker supports GNU-style version scripts
-- CMAKE_EXECUTABLE_SUFFIX = 
-- Looking for a ASM_NASM compiler
-- Looking for a ASM_NASM compiler - /usr/bin/nasm
-- The ASM_NASM compiler identification is NASM
-- Found assembler: /usr/bin/nasm
-- CMAKE_ASM_NASM_COMPILER = /usr/bin/nasm
-- CMAKE_ASM_NASM_OBJECT_FORMAT = elf64
-- CMAKE_ASM_NASM_FLAGS =  -DELF -D__x86_64__ -DPIC 
-- SIMD extensions: x86_64 (WITH_SIMD = 1)
-- PNG reading support enabled (PNG_SUPPORTED = 1)
-- Found ZLIB: /lib/libz.so (found version "1.2.11") 
-- Found PNG: /usr/lib/libpng.so (found suitable version "1.6.37", minimum required is "1.6") 
-- PNG reading support enabled (PNG_SUPPORTED = 1)
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.11")
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find PNG (missing: PNG_LIBRARY) (Required is at least version
  "1.6")
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake/Modules/FindPNG.cmake:159 (find_package_handle_standard_args)
  CMakeLists.txt:698 (find_package)


-- Configuring incomplete, errors occurred!
See also "/root/build/CMakeFiles/CMakeOutput.log".
See also "/root/build/CMakeFiles/CMakeError.log".

Description

In output.txt, there are some weird error messages that I think make little sense:

-- Found ZLIB: /lib/libz.so (found version "1.2.11") 
-- Found PNG: /usr/lib/libpng.so (found suitable version "1.6.37", minimum required is "1.6") 
-- PNG reading support enabled (PNG_SUPPORTED = 1)
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.11")
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find PNG (missing: PNG_LIBRARY) (Required is at least version
  "1.6")

Although I have installed both zlib-dev and libpng-dev, and cmake can also find where I installed. (/usr/lib/libpng.so and /lib/libz.so respectively), somehow cmake keeps arguing it cannot find ZLIB_LIBRARY PNG_LIBRARY.

Workaround

A workaround is to disable png support by -D PNG_SUPPORTED=FALSE, for example, the following command can build successfully:

docker run --rm -i alpine:3.14.0 sh <<EOS
set -euo pipefail
apk add cmake make gcc musl-dev curl nasm
cd ~
curl -LSs https://github.com/mozilla/mozjpeg/archive/refs/tags/v4.0.3.tar.gz | tar -xz
mkdir build
cd build
cmake -G"Unix Makefiles" -D PNG_SUPPORTED=FALSE ../mozjpeg-4.0.3
EOS

Question

I wonder how I can build mozjpeg with png support? Did I miss anything?

I would appreciate your help.

tonytonyjan avatar Jul 01 '21 16:07 tonytonyjan

Could NOT find ZLIB (missing: ZLIB_LIBRARY) (found version "1.2.11")

This paradox is caused by cmake being super confused when both libpng and zlib aren't either both static or both dynamic. I don't know if it's fixable. C dependencies are such a pain :(

kornelski avatar Jul 01 '21 20:07 kornelski

Build shared and static library saperately.

Something like

# Build shared
mkdir build-shared && cd build-shared
cmake .. -DENABLE_SHARED=1 -DENABLE_STATIC=0
make

# Build static
mkdir build-static && cd build-static
cmake .. -DENABLE_SHARED=0 -DENABLE_STATIC=1
make

I think we should change build script to disallow building shared and static at same time. But this change may break CIs. https://github.com/libjpeg-turbo/libjpeg-turbo/pull/458

dofuuz avatar Jul 31 '21 01:07 dofuuz

You should install libpng-devel to build mozjpeg with PNG support on Linux.

DKLIMASHIN avatar Nov 23 '22 11:11 DKLIMASHIN