fatal error: 'png.h' file not found — 如何将 r 安装包从源指向 opt/homebrew/include/png.h

问题描述 投票:0回答:1

Apple M1 在从源安装时要查找的 R 包预期库中没有

png.h

我是用自制软件安装的,

> brew install libpng

安装

png.h
到,

/opt/homebrew/Cellar/libpng/1.6.39/include/libpng16/png.h

带有符号链接,

/opt/homebrew/include/png.h

当我尝试安装包时,

install.packages("ggiraph", type = "source")

我得到错误,

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>
         ^~~~~~~
r apple-m1 install.packages
1个回答
1
投票

如果您从 CRAN 二进制文件而不是源代码安装 R,那么您应该使用 here 托管的二进制文件安装外部库,而不是来自 Homebrew,其二进制文件可能与 CRAN 不兼容。在你的情况下,我会尝试:

$ 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 /

应该在

libpng
下安装
/opt/R/arm64
,其中 CRAN 配置 R 以查找外部库。您可以使用
R CMD config
:

查询默认搜索路径
$ R CMD config CPPFLAGS
-I/opt/R/arm64/include
$ R CMD config LDFLAGS
-L/opt/R/arm64/lib

如果您坚持使用 Homebrew 安装,则通过设置

PKG_CPPFLAGS
PKG_LIBS
添加到默认搜索路径:

$ PKG_CPPFLAGS=-I/opt/homebrew/include R -e "install.packages(\"ggiraph\", type = \"source\")"
© www.soinside.com 2019 - 2024. All rights reserved.