Apple M1 doesn't have png.h
in the expected libraries for R packages to find when installing from source.
I've installed it using homebrew,
> brew install libpng
which installs png.h
to,
/opt/homebrew/Cellar/libpng/1.6.39/include/libpng16/png.h
with a symlink at,
/opt/homebrew/include/png.h
When I try to install the package,
install.packages("ggiraph", type = "source")
I get the error,
clang++ -arch arm64 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c raster.cpp -o raster.o
In file included from raster.cpp:4:
In file included from ./dsvg.h:7:
In file included from ./dsvg_dev.h:7:
./interactive.h:23:9: warning: 'InteractiveElements::push' hides overloaded virtual function [-Woverloaded-virtual]
INDEX push(SVGElement* el);
^
./indexed.h:29:17: note: hidden overloaded virtual function 'IndexedElements::push' declared here: different number of parameters (2 vs 1)
virtual INDEX push(SVGElement* el, const bool& add_id = true);
^
In file included from raster.cpp:4:
In file included from ./dsvg.h:7:
In file included from ./dsvg_dev.h:8:
./clip.h:27:9: warning: 'Clips::push' hides overloaded virtual function [-Woverloaded-virtual]
INDEX push(SVGElement* el, const char* key = NULL);
^
./indexed.h:29:17: note: hidden overloaded virtual function 'IndexedElements::push' declared here: type mismatch at 2nd parameter ('const bool &' vs 'const char *')
virtual INDEX push(SVGElement* el, const bool& add_id = true);
^
raster.cpp:7:10: fatal error: 'png.h' file not found
#include <png.h>
^~~~~~~
If you installed R from a CRAN binary rather than from sources, then you should be installing external libraries using the binaries hosted here rather than from Homebrew, whose binaries may not be compatible with CRAN's. In your case, I would try:
$ curl -LO https://mac.r-project.org/bin/darwin20/arm64/libpng-1.6.38-darwin.20-arm64.tar.xz
$ sudo tar -xvf libpng-1.6.38-darwin.20-arm64.tar.xz -C /
That should install libpng
under /opt/R/arm64
, where CRAN configures R to find external libraries. You can query the default search paths using R CMD config
:
$ R CMD config CPPFLAGS
-I/opt/R/arm64/include
$ R CMD config LDFLAGS
-L/opt/R/arm64/lib
If you insist on using your Homebrew installation, then add to the default search paths by setting PKG_CPPFLAGS
and PKG_LIBS
:
$ PKG_CPPFLAGS=-I/opt/homebrew/include R -e "install.packages(\"ggiraph\", type = \"source\")"