Re: [Rd] How to get R to compile with PNG support

From: Matt Shotwell <Matt.Shotwell_at_vanderbilt.edu>
Date: Thu, 21 Apr 2011 08:21:37 -0500

On 04/19/2011 05:00 AM, r-devel-request_at_r-project.org wrote:
> Date: Mon, 18 Apr 2011 11:48:40 -0400
> From: Karl-Dieter Crisman<kcrisman_at_gmail.com>
> To:r-devel_at_r-project.org
> Cc: Jason Grout<jason.grout_at_drake.edu>
> Subject: [Rd] How to get R to compile with PNG support
> Message-ID:<BANLkTinQz7eOE7b-GpBRcNRhcY0-bdc4Eg@mail.gmail.com>
> Content-Type: text/plain; charset=windows-1252
>
> Dear R devel list,
>
> Good morning; I'm with the Sage (http://www.sagemath.org) project.
> (Some of you might have seen my talk on this at last summer's useR
> conference).
>
> We have some rudimentary support for using R graphics in various
> cases, which has proved useful to many of our users who want to go
> back and forth between R and other capabilities within Sage.
> Unfortunately, the way we originally implemented this was using the
> png and plot functions in R itself, which perhaps isn't the best
> (i.e., everyone uses ggplot now? but I digress).
>
> That means that when people download a binary of ours, or compile
> their own, whether R's plot and png functions work depends heavily on
> the rather obscure (to users) issue of exactly what headers are
> present on the compiling machine.
>
> Unfortunately, it is*very* unclear what actually needs to be present!
> There are innumerable places where this has come up for us, but
> http://trac.sagemath.org/sage_trac/ticket/8868 and
> http://ask.sagemath.org/question/192/compiling-r-with-png-support are
> two of the current places where people have compiled information.
>
> The FAQ says, "Unless you do not want to view graphs on-screen you
> need ?X11? installed, including its headers and client libraries. For
> recent Fedora distributions it means (at least) ?libX11?,
> ?libX11-devel?, ?libXt? and ?libXt-devel?. On Debian we recommend the
> meta-package ?xorg-dev?. If you really do not want these you will need
> to explicitly configure R without X11, using --with-x=no."
>
> Well, we don't actually need to view graphs on-screen, but we do need
> to be able to generate them and save them (as pngs, for instance) to
> the correct directory in Sage for viewing. But we have people who've
> tried to do this in Ubuntu, with libpng and xorg-dev installed, and
> the file /usr/include/X11/Xwindows.h exists, but all to no avail.
> There are almost as many solutions people have found as there are
> computers out there, it seems - slight hyperbole, but that's what it
> feels like.
>
> We've posted more than once (I think) to the r-help list, but have
> gotten no useful feedback. Is there*anywhere* that the*exact*
> requirements R has for having
>
> capabilities("png")
> png
> FALSE
>
> come out TRUE are documented?

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.

> Then, not only could we be smarter in how we compile R (currently
> somewhat naively searching for /usr/include/X11/Xwindows.h to
> determine whether we'll try for png support), but we would be able to
> tell users something very precise to do (e.g., apt-get foo) if they
> currently have R without PNG support in Sage. Again, I emphasize that
> apparently getting xorg-dev doesn't always do the trick.
>
> We do realize that for most people wanting to use just R, it's best to
> download a binary, which will behave nicely; Sage's "batteries
> included" philosophy means that we are asking for more specialized
> info from upstream, and for that I apologize in advance. I also
> apologize if I said something silly above, because I don't actually
> know what all these files are - I've just looked into enough support
> requests to have a decent idea of what's required. We are trying
> not to have to parse the makefile to figure all this out, and possibly
> making some mistake there as well.
>
> Thank you SO much for any help with this,
> Karl-Dieter Crisman
> for the Sage team
>
>

-- 
Matthew S Shotwell   Assistant Professor           School of Medicine
                      Department of Biostatistics   Vanderbilt University

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu 21 Apr 2011 - 13:29:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 21 Apr 2011 - 14:00:50 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive