Search code examples
phpcunixbuildlibjpeg

libjpeg not found building PHP from source at configure stage, FreeBSD


I'm trying to build PHP 8.4 from source with GD enabled on Unix

root@dev:/ # uname -a
FreeBSD dev 14.2-RELEASE FreeBSD 14.2-RELEASE releng/14.2-n269506-c8918d6c7412 GENERIC amd64

I've compiled from source libjpeg (trying versions 6b, 7, 8 and 9) from https://www.ijg.org/files/ using:

./configure --enable-shared --enable-static

With resulting files:

dir /usr/local/lib/*jpeg*
-rw-r--r--  1 root wheel 2039538 Feb 15 12:25 /usr/local/lib/libjpeg.a
-rwxr-xr-x  1 root wheel     868 Feb 15 12:25 /usr/local/lib/libjpeg.la
lrwxr-xr-x  1 root wheel      12 Feb 14 12:52 /usr/local/lib/libjpeg.so -> libjpeg.so.9
-rwxr-xr-x  1 root wheel 1097904 Feb 14 12:52 /usr/local/lib/libjpeg.so.9
-rw-r--r--  1 root wheel 1482374 Jan 30 03:03 /usr/local/lib/libturbojpeg.a
lrwxr-xr-x  1 root wheel      17 Jan 30 03:03 /usr/local/lib/libturbojpeg.so -> libturbojpeg.so.0
lrwxr-xr-x  1 root wheel      21 Jan 30 03:03 /usr/local/lib/libturbojpeg.so.0 -> libturbojpeg.so.0.3.0
-rwxr-xr-x  1 root wheel  976216 Jan 30 03:03 /usr/local/lib/libturbojpeg.so.0.3.0

Everything I try to configure PHP I get Package 'libjpeg' not found

My configure command:

./configure --with-apxs2=/usr/local/apache/bin/apxs \
--with-config-file-path=/usr/local/etc \
--enable-bcmath --without-cdb \
--enable-gd --without-iodbc --enable-inline-optimization \
--without-gdbm --with-ndbm --without-db2 --without-dbm \
--without-readline --without-recode --with-openssl \
--without-db3 --enable-dba \
--with-curl \
--with-jpeg --enable-calendar \
--with-mhash --enable-mbstring=all \
--with-zlib \
--with-png-dir=/usr/local/libpng/lib \
--with-freetype --with-pdo-mysql \
--enable-exif --enable-zip \
--without-libzip \
--with-mysqli=mysqlnd \
--without-sqlite3

Searching config.log for 'jpeg' shows that it seems to find it on for first time it looks, but then fails the second time.

configure:35077: checking for libjpeg
configure:35094: result: yes

...


configure:36211: checking for libjpeg
configure:36218: $PKG_CONFIG --exists --print-errors "libjpeg"
Package libjpeg was not found in the pkg-config search path.
Perhaps you should add the directory containing `libjpeg.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libjpeg' not found
configure:36221: $? = 1
configure:36235: $PKG_CONFIG --exists --print-errors "libjpeg"
Package libjpeg was not found in the pkg-config search path.
Perhaps you should add the directory containing `libjpeg.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libjpeg' not found
configure:36238: $? = 1
configure:36252: result: no
Package 'libjpeg' not found
configure:36277: error: Package requirements (libjpeg) were not met:

Package 'libjpeg' not found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables JPEG_CFLAGS
and JPEG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

I'm not a C programmer and not too familiar with the build process, so some help would be appreciated. I googles about the suggestions configure listed but could not find anything useful.

EDIT As per comments, I installed ver 9f of libjpeg

root@dev:/usr/local/jpeg-9f # make install
 mkdir -p '/usr/local/lib'
 /bin/sh ./libtool   --mode=install /usr/bin/install -c   libjpeg.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libjpeg.so.9.6.0 /usr/local/lib/libjpeg.so.9.6.0
libtool: install: (cd /usr/local/lib && { ln -s -f libjpeg.so.9.6.0 libjpeg.so.9 || { rm -f libjpeg.so.9 && ln -s libjpeg.so.9.6.0 libjpeg.so.9; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libjpeg.so.9.6.0 libjpeg.so || { rm -f libjpeg.so && ln -s libjpeg.so.9.6.0 libjpeg.so; }; })
libtool: install: /usr/bin/install -c .libs/libjpeg.lai /usr/local/lib/libjpeg.la
libtool: install: /usr/bin/install -c .libs/libjpeg.a /usr/local/lib/libjpeg.a
libtool: install: chmod 644 /usr/local/lib/libjpeg.a
libtool: install: ranlib /usr/local/lib/libjpeg.a
 mkdir -p '/usr/local/bin'
  /bin/sh ./libtool   --mode=install /usr/bin/install -c cjpeg djpeg jpegtran rdjpgcom wrjpgcom '/usr/local/bin'
libtool: install: /usr/bin/install -c .libs/cjpeg /usr/local/bin/cjpeg
libtool: install: /usr/bin/install -c .libs/djpeg /usr/local/bin/djpeg
libtool: install: /usr/bin/install -c .libs/jpegtran /usr/local/bin/jpegtran
libtool: install: /usr/bin/install -c rdjpgcom /usr/local/bin/rdjpgcom
libtool: install: /usr/bin/install -c wrjpgcom /usr/local/bin/wrjpgcom
/bin/sh /usr/local/jpeg-9f/install-sh -d /usr/local/include
/usr/bin/install -c -m 644 jconfig.h /usr/local/include/jconfig.h
 mkdir -p '/usr/local/include'
 /usr/bin/install -c -m 644 jerror.h jmorecfg.h jpeglib.h '/usr/local/include'
 mkdir -p '/usr/local/share/man/man1'
 /usr/bin/install -c -m 644 cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 wrjpgcom.1 '/usr/local/share/man/man1'
 mkdir -p '/usr/local/lib/pkgconfig'

 /usr/bin/install -c -m 644 libjpeg.pc '/usr/local/lib/pkgconfig'

libjpeg.pc is present:

/usr/local/lib/pkgconfig/libjpeg.pc

However still getting same issue when I configure PHP (I deleted config.log/nice before trying again)

setenv PKG_CONFIG_PATH /usr/local/lib/pkgconfig

Seems to have worked, now failing on iconv supports errno... no

checking for libjpeg... yes
checking for libXpm... no
checking for FreeType 2... yes
checking whether to enable JIS-mapped Japanese font support in GD... no
checking for zlib >= 1.2.11... yes
checking for libpng... yes
checking for libjpeg... yes
checking for freetype2... yes
checking whether build works... yes
checking for GNU gettext support... no
checking for GNU MP support... no
checking for mhash support... yes
configure: WARNING: The --with-mhash option and mhash* functions are deprecated as of PHP 8.1.0
checking size of long... (cached) 8
checking if we're at 64-bit platform... yes
checking for iconv support... yes
checking for iconv... yes
checking for iconv implementation... GNU libiconv
checking if iconv supports errno... no
configure: error: in '/usr/local/dev_build_sources/php-8.4.3':
configure: error: The iconv check failed, 'errno' is missing.

Solution

  • This error:

    Package 'libjpeg' not found
    
    Consider adjusting the PKG_CONFIG_PATH environment variable if you
    installed software in a non-standard prefix.
    

    indicates that package config for libjpeg is not found. Since libjpeg was built manually and libjpeg.pc exists in /usr/local/lib/pkgconfig/libjpeg.pc which is not searched by default on FreeBSD you have to set PKG_CONFIG_PATH manually using tcsh syntax:

    $ setenv PKG_CONFIG_PATH /usr/local/lib/pkgconfig
    

    That should solve the problem with libjpeg at ./configure step but, depending on how a dynamic linker on FreeBSD is working it might be necessary to manually set LD_LIBRARY_PATH to run php with /usr/local/lib/libjpeg.so.