Subject: 25.1; configure.ac libpng search error
From: "James K. Lowden" <[email-masked]>
To: [email-masked]
Date: Sat, 24 Dec 2016 16:31:08 -0500
List-Id: <debbugs-submit.debbugs.gnu.org>

configure.ac uses libpng-config, if installed, to determine the include
directive for the PNG library.  Unfortuately, it does not correctly use
libpng-config for the linker flags.  Consequently, it may mismatch the
header file to the library.  In my case, configure misdiagnosed my
setup, and recommended --no-png.

On my system, a libpng-config was installed by the Anaconda scientific
Python package distribution.  Because I had allowed Anaconda to place
itself earlier in the path than /usr/bin, that is the version configure
used.  I suspect the error I describe below has not been detected before
because my setup is unusual.

First, let's see what libpng-config has to say on my system: 

$ for opt in cflags ldflags libs
do
        cmd="libpng-config --$opt"
        printf "%-25s: %-s\n" "$cmd" "$($cmd)"
done
libpng-config --cflags   : -I/usr/local/anaconda/include/libpng16
libpng-config --ldflags  : -L/usr/local/anaconda/lib -lpng16
libpng-config --libs     : -lpng16

Now, let's look at how libpng-config is used in configure.ac:

$ grep -n libpng-config configure.ac
3412:    png_cflags=`(libpng-config --cflags) 2>&AS_MESSAGE_LOG_FD` &&
3413:    png_libs=`(libpng-config --libs) 2>&AS_MESSAGE_LOG_FD` || {
3414:      # libpng-config does not work; configure by hand.

As you can see, png_libs relies on

   libpng-config --libs

not

   libpng-config --ldflags

The produced configure script therefore finds an include file under
ananconda, but does not provide the associated -L option to the
linker.  The configure test fails because a symbol declared in the
header file is not supplied by the (older) libpng found by the linker.  

I believe the fix is to change line 3413 of configure.ac to read:

    png_libs=`(libpng-config --ldflags) 2>&AS_MESSAGE_LOG_FD` || {

although IMO that's not quite sufficient, because it doesn't set RPATH.  

I worked around the problem before completely diagnosing it simply by
renaming /usr/local/anaconda to /usr/local/.anaconda, taking it out of
the PATH and causing configure not to find it.  The outputs are:

    $ /usr/bin/libpng-config --cflags --libs
    -I/usr/include/libpng12
    -lpng12

which worked just fine.  In fact, I used report-emacs-bug in the newly
built emacs to send this message.

The rest of this message was produced by report-emacs-bug.  I include it
in case there are details you can use.

Humbly submitted,

--jkl

In GNU Emacs 25.1.2 (x86_64-unknown-linux-gnu, GTK+ Version 3.18.9)
 of 2016-12-17 built on willow.schemamania.org
Windowing system distributor 'The X.Org Foundation', version 11.0.11804000
System Description:	Ubuntu 16.04.1 LTS

Configured using:
 'configure --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
 --without-dbus --without-gconf --without-gsettings'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM NOTIFY ACL LIBSELINUX
GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS
GTK3 X11

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: GNUmakefile

Minor modes in effect:
  shell-dirtrack-mode: t
  diff-auto-refine-mode: t
  recentf-mode: t
  global-ede-mode: t
  ede-minor-mode: t
  global-semanticdb-minor-mode: t
  global-semantic-idle-scheduler-mode: t
  semantic-idle-scheduler-mode: t
  semantic-mode: t
  yas-global-mode: t
  yas-minor-mode: t
  global-auto-complete-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent messages:
[yas] Loading for `makefile-mode', just-in-time: (lambda nil (yas--load-directory-1 (quote /home/jklowden/.emacs.d/elpa/yasnippet-20160416.831/snippets/makefile-mode) (quote makefile-mode)))!
[yas] Loading snippet files from /home/jklowden/.emacs.d/elpa/yasnippet-20160416.831/snippets/makefile-mode
Parsing Makefile (LL)...
[yas] Loading for `text-mode', just-in-time: (lambda nil (yas--load-directory-1 (quote /home/jklowden/.emacs.d/elpa/yasnippet-20160416.831/snippets/text-mode) (quote text-mode)))!
[yas] Loading snippet files from /home/jklowden/.emacs.d/elpa/yasnippet-20160416.831/snippets/text-mode
[yas] Loading for `c-mode', just-in-time: (lambda nil (yas--load-directory-1 (quote /home/jklowden/.emacs.d/elpa/yasnippet-20160416.831/snippets/c-mode) (quote c-mode)))!
[yas] Loading snippet files from /home/jklowden/.emacs.d/elpa/yasnippet-20160416.831/snippets/c-mode
[yas] Loading for `cc-mode', just-in-time: (lambda nil (yas--load-directory-1 (quote /home/jklowden/.emacs.d/elpa/yasnippet-20160416.831/snippets/cc-mode) (quote cc-mode)))!
[yas] Loading snippet files from /home/jklowden/.emacs.d/elpa/yasnippet-20160416.831/snippets/cc-mode
Parsing prim-workalike/Makefile (LL)...done

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message dired rfc822 mml mml-sec epg
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mail-utils
semantic/tag-file semantic/bovine/c hideif semantic/bovine/c-by
semantic/lex-spp semantic/bovine/gcc semantic/analyze/refs
auto-complete-c-headers tramp tramp-compat auth-source gnus-util mm-util
help-fns mail-prsvr password-cache tramp-loaddefs trampver ucs-normalize
shell pcomplete format-spec cc-mode cc-fonts cc-guess cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs nroff-mode vc-git diff-mode
easy-mmode semantic/db-file data-debug cedet-files semantic/bovine/make
semantic/decorate/include semantic/db-find semantic/db-ref
semantic/decorate/mode semantic/decorate pulse semantic/dep
semantic/analyze semantic/sort semantic/scope semantic/analyze/fcn
semantic/bovine/make-by semantic/bovine make-mode pp server time-date
recentf tree-widget ede/speedbar ede/files ede ede/detect ede/base
ede/auto ede/source eieio-speedbar speedbar sb-image dframe eieio-custom
wid-edit semantic/db-mode semantic/db eieio-base semantic/idle
semantic/format ezimage semantic/tag-ls semantic/find semantic/ctxt
semantic/util-modes semantic/util semantic semantic/tag semantic/lex
semantic/fw eieio eieio-core mode-local find-func cedet yasnippet advice
flymake compile comint ansi-color ring auto-complete-config
auto-complete popup finder-inf ac-c-headers-autoloads
auto-complete-c-headers-autoloads auto-complete-autoloads avy-autoloads
format-sql-autoloads popup-autoloads sql-indent-autoloads
unbound-autoloads xcscope-autoloads xkcd-autoloads yasnippet-autoloads
package epg-config seq byte-opt bytecomp byte-compile cl-extra help-mode
easymenu cconv cobol-mode derived cl-macs skeleton cl-seq cl gv edmacro
kmacro cl-loaddefs pcase cl-lib mule-util tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese charscript case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer cl-preloaded nadvice loaddefs button faces
cus-face macroexp files text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
inotify dynamic-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty make-network-process emacs)

Memory information:
((conses 16 459597 15119)
 (symbols 48 34093 0)
 (miscs 40 840 561)
 (strings 32 79645 25011)
 (string-bytes 1 2027516)
 (vectors 16 60451)
 (vector-slots 8 1036169 7841)
 (floats 8 1072 263)
 (intervals 56 1709 70)
 (buffers 976 29)
 (heap 1024 69942 1543))