16

I am trying to build the R package png, the repo says that libpng needs to be available.

I run a Linux Fedora 20 distro

Looks like I have it...

[root@localhost bin]# yum install libpng
Loaded plugins: langpacks, refresh-packagekit
Package 2:libpng-1.6.3-3.fc20.x86_64 already installed and latest version
Nothing to do

But when I try to install it:

> install.packages("png")
Installing package into ‘/home/statquant/R/x86_64-redhat-linux-gnu-library/3.0’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/png_0.1-7.tar.gz'
Content type 'application/x-gzip' length 24990 bytes (24 Kb)
opened URL
==================================================
downloaded 24 Kb

* installing *source* package ‘png’ ...
** package ‘png’ successfully unpacked and MD5 sums checked
** libs
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG  -I/usr/local/include    `libpng-config --cflags` -fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic  -c read.c -o read.o
/bin/sh: libpng-config: command not found
read.c:3:17: fatal error: png.h: No such file or directory
 #include <png.h>
                 ^
compilation terminated.
make: *** [read.o] Error 1
ERROR: compilation failed for package ‘png’
* removing ‘/home/statquant/R/x86_64-redhat-linux-gnu-library/3.0/png’

The downloaded source packages are in
        ‘/tmp/RtmpG5MjG9/downloaded_packages’
Warning message:
In install.packages("png") :
  installation of package ‘png’ had non-zero exit status
HDJEMAI
  • 7,766
  • 41
  • 60
  • 81
statquant
  • 12,389
  • 13
  • 75
  • 148
  • 4
    A lot of times the packages need the development package. Try `yum install libpng-devel` and then try reinstalling. – Dason Feb 15 '14 at 17:18
  • you are the one ! it works – statquant Feb 15 '14 at 17:19
  • @Dason, feel free to put that as an answer. – Roman Luštrik Feb 15 '14 at 17:31
  • @RomanLuštrik I haven't used Fedora in ages so I wasn't sure if that was the issue. I'll move it to an answer though. – Dason Feb 15 '14 at 17:35
  • Also worked for me. I built R 2.15.3 from source code and while I had libpng.so files I could link to, I still needed the development package before it would build in the PNG capability. You will see it as one of the 'Additional capabilities' in the configure summary when configure finishes. I didn't install it as a 'package'. – Robert Casey Jun 10 '14 at 23:14

2 Answers2

40

For some R packages you need the corresponding development library to successfully install the R package. In your case this should do what you need

# Do the following in your terminal (not in an R session)
yum install libpng-devel

afterwards you should be able to install the R package

# Do the following in the R console (during an R session)
install.packages("png")
Dason
  • 55,392
  • 9
  • 117
  • 138
7

I had the same problem on Ubuntu (16.04) and solved it using

sudo apt-get install libpng-dev
bwb
  • 83
  • 1
  • 4
  • While we're at non-Fedora distros, for OpenSUSE: simply open YaST, check the libpng installed (in my case libpng16-16), and add the corresponding -devel (in my case libpng16-devel). After that, R had no issues installing the package. – 4rj4n Mar 28 '19 at 10:18
  • I'm using linux mint and this solved the issue for me - thanks :) – Tal Galili Sep 03 '20 at 08:05