2 min read

Quick post about this error you might experience if you're trying to compile a Varnish module from source.

root@varnish001:libvmod-curl# ./autogen.sh 
Package varnishapi was not found in the pkg-config search path.
Perhaps you should add the directory containing `varnishapi.pc'
to the PKG_CONFIG_PATH environment variable

Check if the file exists (it comes from libvarnishapi-dev on Ubuntu):

root@varnish001:libvmod-curl# dpkg -l | grep libvarnishapi-dev
ii  libvarnishapi-dev:amd64                6.2.1-2                               amd64        development files for Varnish
root@varnish001:libvmod-curl# dpkg -L libvarnishapi-dev | grep varnishapi.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/varnishapi.pc
root@varnish001:libvmod-curl# ls -al /usr/lib/x86_64-linux-gnu/pkgconfig/varnishapi.pc
-rw-r--r-- 1 root root 570 Sep  8  2019 /usr/lib/x86_64-linux-gnu/pkgconfig/varnishapi.pc

Try adding this directory as part of PKG_CONFIG_PATH:

root@varnish001:libvmod-curl# PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/usr/lib/x86_64-linux-gnu/pkgconfig ./autogen.sh
Package varnishapi was not found in the pkg-config search path.
Perhaps you should add the directory containing `varnishapi.pc'
to the PKG_CONFIG_PATH environment variable

Try swearing, then check the code:

root@varnish001:libvmod-curl# grep -B5 varnishapi.pc ./autogen.sh 
# check for varnishapi.m4 in custom paths
dataroot=$(pkg-config --variable=datarootdir varnishapi 2>/dev/null)
if [ -z "$dataroot" ] ; then
cat >&2 <<'EOF'
Package varnishapi was not found in the pkg-config search path.
Perhaps you should add the directory containing `varnishapi.pc'

It comes from pkg-config --variable=datarootdir varnishapi. Try running that without sending STDERR to /dev/null:

root@varnish001:libvmod-curl# pkg-config --variable=datarootdir varnishapi

Command 'pkg-config' not found, but can be installed with:

apt install pkg-config  # version 0.29.1-0ubuntu4, or
apt install pkgconf     # version 1.6.3-5

Install pkg-config, and it should work now:

root@varnish001:libvmod-curl# ./autogen.sh 
+ libtoolize --copy --force
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
+ aclocal -I m4 -I /usr/share/aclocal
+ autoheader
+ automake --add-missing --copy --foreign
configure.ac:13: installing './compile'
configure.ac:8: installing './config.guess'
configure.ac:8: installing './config.sub'
configure.ac:11: installing './install-sh'
configure.ac:11: installing './missing'
src/Makefile.am: installing './depcomp'
parallel-tests: installing './test-driver'
+ autoconf
James Lawrie

James Lawrie

James has over a decade of experience working for companies such as Percona, UKFast, and Bytemark. In his spare time he rides his motorbike, lifts weights, and learns Polish.