r-lib / svglite

A lightweight svg graphics device for R
https://svglite.r-lib.org
180 stars 39 forks source link

installation from source fails on arm64 if incompatible /usr/local/lib/libpng.dylib exists #169

Closed kevinushey closed 1 month ago

kevinushey commented 1 year ago

For reference, the installation log:

* installing *source* package ‘svglite’ ...
** package ‘svglite’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C++ compiler: ‘Apple clang version 14.0.3 (clang-1403.0.22.14.1)’
using C++11
using SDK: ‘’
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Users/kevin/Library/R/arm64/4.3/library/cpp11/include' -I'/Users/kevin/Library/R/arm64/4.3/library/systemfonts/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'/Users/kevin/Library/R/arm64/4.3/library/cpp11/include' -I'/Users/kevin/Library/R/arm64/4.3/library/systemfonts/include' -I/opt/R/arm64/include    -fPIC  -falign-functions=64 -Wall -g -O2  -c devSVG.cpp -o devSVG.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 svglite.so cpp11.o devSVG.o -lpng -lz -L/opt/homebrew/opt/libomp/lib -lomp -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: ignoring file /usr/local/lib/libpng.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
installing to /Users/kevin/Library/R/arm64/4.3/library/00LOCK-svglite/00new/svglite/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘svglite’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/kevin/Library/R/arm64/4.3/library/00LOCK-svglite/00new/svglite/libs/svglite.so':
  dlopen(/Users/kevin/Library/R/arm64/4.3/library/00LOCK-svglite/00new/svglite/libs/svglite.so, 0x0006): symbol not found in flat namespace '_png_create_info_struct'
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Users/kevin/Library/R/arm64/4.3/library/svglite’
Warning in install.packages("svglite", type = "source") :
  installation of package 'svglite' had non-zero exit status

Would it be worth including a configure script that prefers libraries found in /opt/homebrew/lib if on arm64 macOS?

kevinushey commented 1 year ago

(you could also argue it's my fault for having both an x86_64 installation of Homebrew in /usr/local, as well as the regular arm64 installation in /opt/homebrew ...)

DavisVaughan commented 1 year ago

I also have this issue!

I think systemfonts gets around this by having a configure script that generates the Makevars: https://github.com/r-lib/systemfonts/blob/main/configure https://github.com/r-lib/systemfonts/blob/main/src/Makevars.in

which for me makes:

CXX_STD = CXX11

PKG_CPPFLAGS=-I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/opt/libpng/include/libpng16
PKG_OBJCXXFLAGS=-fobjc-arc

DARWIN_LIBS = -framework CoreText -framework Foundation
DARWIN_OBJECTS = mac/FontManagerMac.o
UNIX_OBJECTS = unix/FontManagerLinux.o

PKG_LIBS = -L/opt/homebrew/opt/freetype/lib -L/opt/homebrew/opt/libpng/lib -lfreetype -lbz2 -lpng16 -lz $(DARWIN_LIBS)
OBJECTS = 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 $(DARWIN_OBJECTS)

all: clean

clean:
    rm -f $(SHLIB) $(OBJECTS)

and that works well