r-lib / systemfonts

System Native Font Handling in R
https://systemfonts.r-lib.org
Other
92 stars 17 forks source link

Compilation error in MacOS Monterey: library not found for -lpng16 #102

Open solmos opened 1 year ago

solmos commented 1 year ago

I can't install systemfonts in MacOS Monterrey with M1:

> install.packages("systemfonts")
Installing package into ‘/Users/I0542459/Library/R/arm64/4.2/library’
(as ‘lib’ is unspecified)
Package which is only available in source form, and may need
  compilation of C/C++/Fortran: ‘systemfonts’
Do you want to attempt to install these from sources? (Yes/no/cancel) yes
installing the source package ‘systemfonts’

trying URL 'https://packagemanager.rstudio.com/cran/latest/src/contrib/systemfonts_1.0.4.tar.gz'
Content type 'binary/octet-stream' length 81941 bytes (80 KB)
==================================================
downloaded 80 KB

* installing *source* package ‘systemfonts’ ...
** package ‘systemfonts’ successfully unpacked and MD5 sums checked
** using staged installation
Found pkg-config cflags and libs!
Using PKG_CFLAGS=-I/opt/homebrew/opt/freetype/include/freetype2
Using PKG_LIBS=-L/opt/homebrew/opt/freetype/lib -L/opt/homebrew/Cellar/libpng/1.6.37/lib -lfreetype -lz -lbz2 -lpng16 -lz
** libs
rm -f systemfonts.so caches.o cpp11.o dev_metrics.o font_matching.o font_registry.o ft_cache.o string_shape.o font_metrics.o font_fallback.o string_metrics.o emoji.o cache_store.o init.o mac/FontManagerMac.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c caches.cpp -o caches.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c cpp11.cpp -o cpp11.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c dev_metrics.cpp -o dev_metrics.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c font_matching.cpp -o font_matching.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c font_registry.cpp -o font_registry.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c ft_cache.cpp -o ft_cache.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c string_shape.cpp -o string_shape.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c font_metrics.cpp -o font_metrics.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c font_fallback.cpp -o font_fallback.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c string_metrics.cpp -o string_metrics.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c emoji.cpp -o emoji.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c cache_store.cpp -o cache_store.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c init.cpp -o init.o
clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/freetype/include/freetype2 -I'/Users/I0542459/Library/R/arm64/4.2/library/cpp11/include' -I/opt/R/arm64/include  -fobjc-arc -fPIC   -c mac/FontManagerMac.mm -o mac/FontManagerMac.o
clang++ -arch arm64 -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o systemfonts.so caches.o cpp11.o dev_metrics.o font_matching.o font_registry.o ft_cache.o string_shape.o font_metrics.o font_fallback.o string_metrics.o emoji.o cache_store.o init.o mac/FontManagerMac.o -L/opt/homebrew/opt/freetype/lib -L/opt/homebrew/Cellar/libpng/1.6.37/lib -lfreetype -lz -lbz2 -lpng16 -lz -framework CoreText -framework Foundation -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/opt/homebrew/Cellar/libpng/1.6.37/lib'
ld: library not found for -lpng16
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [systemfonts.so] Error 1
ERROR: compilation failed for package ‘systemfonts’
* removing ‘/Users/I0542459/Library/R/arm64/4.2/library/systemfonts’
* restoring previous ‘/Users/I0542459/Library/R/arm64/4.2/library/systemfonts’

The downloaded source packages are in
    ‘/private/var/folders/gx/vdqbfzvs66b1swy4qv7pch7c0000gp/T/Rtmp2vYZKE/downloaded_packages’
Warning message:
In install.packages("systemfonts") :
  installation of package ‘systemfonts’ had non-zero exit status

I installed libpng with homebrew.

My session info is:

> sessionInfo()
R version 4.2.2 (2022-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.5.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.2.2 tools_4.2.2   
thomasp85 commented 1 year ago

Is the opt/homebrew/Cellar/libpng/1.6.37/lib directory existing?

libpng is often provided directly from the R installation so maybe your home-brew installation has messed that up?