致命错误:未找到“png.h”文件-如何将r install包从源指向opt/homebrew/include/png.h

u59ebvdq  于 2023-03-27  发布在  其他
关注(0)|答案(1)|浏览(204)

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>
         ^~~~~~~
zwghvu4y

zwghvu4y1#

如果你是从CRAN二进制文件而不是从源代码安装R,那么你应该使用here托管的二进制文件安装外部库,而不是从Homebrew安装,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 /

这应该在/opt/R/arm64下安装libpng,其中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_CPPFLAGSPKG_LIBS添加到默认搜索路径:

$ PKG_CPPFLAGS=-I/opt/homebrew/include R -e "install.packages(\"ggiraph\", type = \"source\")"

相关问题