Skip to content

How to get R to compile with PNG support

1 message · Matt Shotwell

#
On 04/19/2011 05:00 AM, r-devel-request at r-project.org wrote:
I had a similar question some time ago. The answer (of course) is in the 
code and configure macros. The main logic is in 
src/main/platform.c::do_capabilities:

     SET_STRING_ELT(ansnames, i, mkChar("png"));
#ifdef HAVE_PNG
# if defined Unix && !defined HAVE_WORKING_CAIRO
     LOGICAL(ans)[i++] = X11;
# else /* Windows */
     LOGICAL(ans)[i++] = TRUE;
# endif
#else
     LOGICAL(ans)[i++] = FALSE;
#endif

-------------------------------

 From m4/R.m4:

if test "${use_libpng}" = yes; then
   AC_CHECK_LIB(z, main, [have_png=yes], [have_png=no])
   if test "${have_png}" = yes; then
     _R_HEADER_PNG
     have_png=${r_cv_header_png_h}
   fi
   if test "${have_png}" = yes; then
     AC_CHECK_LIB(png, png_create_write_struct,
                  [have_png=yes],
                  [have_png=no],
                  [-lz ${LIBS}])
   fi
   if test "${have_png}" = yes; then
     BITMAP_LIBS="${BITMAP_LIBS} -lpng -lz"
     AC_DEFINE(HAVE_PNG, 1,
               [Define if you have the PNG headers and libraries.])
   fi
fi

---------------------------------------

HAVE_WORKING_CAIRO is set by m4/cairo.m4. However, the PNG function 
doesn't consult capabilities("png"). Presumably capabilities("png") is 
sufficient, but you'll have to pick up the trail in the png function to 
find out what's really going on.

I've had good outcomes with cairo.