r-lib / ragg

Graphic Devices Based on AGG
https://ragg.r-lib.org
Other
172 stars 24 forks source link

Question about macOS M1 installation failure ('jpeglib.h' file not found) #115

Closed dantonnoriega closed 2 years ago

dantonnoriega commented 2 years ago

Let me start off by saying that I eventually installed ragg after some trial and error.

I'm here to help others and to see if I can get help understanding my own solutions. Because frankly, I don't.

TLDR

Adding the following to my empty ~/.R/Makevars did the trick.

~/.R/Makevars

BREWDIR:=$(shell brew --prefix)
CPPFLAGS=-I$(BREWDIR)/include
LDFLAGS=-L$(BREWDIR)/lib

What left me confused is why passing INCLUDE_DIR and LIB_DIR did not work.

Below are my other failed attempts. All are installing from source.

Installation Attempts

To start off, I confirmed, looking at configure, that I had all the right libraries installed via homebrew:

❯ brew --prefix
/opt/homebrew
❯ brew ls --versions freetype libpng libtiff zlib libjpeg-turbo
freetype 2.12.1
jpeg-turbo 2.1.3
libpng 1.6.37
libtiff 4.4.0_1
zlib 1.2.12

Attempt 01 -- Empty Makevars & no configure.vars

❯ Rscript -e "install.packages('ragg', type = 'source')"

Pasting the relevant parts of in the failed installation ('jpeglib.h' file not found)

Found pkg-config cflags and libs!
Using PKG_CFLAGS=-I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include
Using PKG_LIBS=-L/opt/homebrew/opt/freetype/lib -L/opt/homebrew/Cellar/libpng/1.6.37/lib -L/opt/homebrew/Cellar/libtiff/4.4.0_1/lib -lfreetype -lz -lbz2 -lpng16 -lz -lpng16 -lz -ltiff -ljpeg -lz -ljpeg
-----------------------------[ ANTICONF ]-------------------------------
Configuration failed to find one of --static freetype2 libpng libtiff-4. Try installing:
 * deb: libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev (Debian, Ubuntu, etc)
 * rpm: freetype-devel libpng-devel libtiff-devel libjpeg-turbo-devel (Fedora, CentOS, RHEL)
 * csw: libfreetype_dev libpng16_dev libtiff_dev libjpeg_dev (Solaris)
If --static freetype2 libpng libtiff-4 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a --static freetype2 libpng libtiff-4.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
-------------------------- [ERROR MESSAGE] ---------------------------
<stdin>:4:10: fatal error: 'jpeglib.h' file not found
#include <jpeglib.h>
         ^~~~~~~~~~~
1 error generated.
--------------------------------------------------------------------

Attempt 02 -- Empty Makevars & update configure.vars

Added appropriate INCLUDE_DIR and LIB_DIR to configure.vars.

❯ Rscript -e "install.packages('ragg', type = 'source', configure.vars = 'INCLUDE_DIR=/opt/homebrew/include LIB_DIR=/opt/homebrew/lib')"

Fails but this time it's 'ft2build.h' file not found.

Found INCLUDE_DIR and/or LIB_DIR!
Using PKG_CFLAGS=-I/opt/homebrew/include
Using PKG_LIBS=-L/opt/homebrew/lib -lfreetype -lpng16 -ltiff -lz -ljpeg -lbz2
-----------------------------[ ANTICONF ]-------------------------------
Configuration failed to find one of --static freetype2 libpng libtiff-4. Try installing:
 * deb: libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev (Debian, Ubuntu, etc)
 * rpm: freetype-devel libpng-devel libtiff-devel libjpeg-turbo-devel (Fedora, CentOS, RHEL)
 * csw: libfreetype_dev libpng16_dev libtiff_dev libjpeg_dev (Solaris)
If --static freetype2 libpng libtiff-4 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a --static freetype2 libpng libtiff-4.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
-------------------------- [ERROR MESSAGE] ---------------------------
<stdin>:1:10: fatal error: 'ft2build.h' file not found
#include <ft2build.h>
         ^~~~~~~~~~~~
1 error generated.
--------------------------------------------------------------------

Attempt 03 -- Update Makevars & no other adjustments

At this point I was confused and I just took an educated guess with my Makevars.

~/.R/Makevars

BREWDIR:=$(shell brew --prefix)
CPPFLAGS=-I$(BREWDIR)/include
LDFLAGS=-L$(BREWDIR)/lib

Then it installed just fine.

❯ Rscript -e "install.packages('ragg', type = 'source')"
* installing *source* package ‘ragg’ ...
** package ‘ragg’ 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 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include
Using PKG_LIBS=-L/opt/homebrew/opt/freetype/lib -L/opt/homebrew/Cellar/libpng/1.6.37/lib -L/opt/homebrew/Cellar/libtiff/4.4.0_1/lib -lfreetype -lz -lbz2 -lpng16 -lz -lpng16 -lz -ltiff -ljpeg -lz -ljpeg
** libs
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c capture_dev.cpp -o capture_dev.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c init.cpp -o init.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c jpeg_dev.cpp -o jpeg_dev.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c png_dev.cpp -o png_dev.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c ppm_dev.cpp -o ppm_dev.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c tiff_dev.cpp -o tiff_dev.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c agg/src/agg_curves.cpp -o agg/src/agg_curves.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c agg/src/agg_font_freetype.cpp -o agg/src/agg_font_freetype.o
agg/src/agg_font_freetype.cpp:116:18: warning: variable 'len' set but not used [-Wunused-but-set-variable]
        unsigned len = 0;
                 ^
1 warning generated.
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c agg/src/agg_image_filters.cpp -o agg/src/agg_image_filters.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c agg/src/agg_trans_affine.cpp -o agg/src/agg_trans_affine.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c agg/src/agg_vcgen_dash.cpp -o agg/src/agg_vcgen_dash.o
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/systemfonts/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/textshaping/include' -I/opt/homebrew/include  -I./agg/include -I/opt/homebrew/opt/freetype/include/freetype2 -I/opt/homebrew/Cellar/libpng/1.6.37/include/libpng16 -I/opt/homebrew/Cellar/libtiff/4.4.0_1/include -fPIC  -falign-functions=64 -Wall -g -O2  -c agg/src/agg_vcgen_stroke.cpp -o agg/src/agg_vcgen_stroke.o
ar rcs agg/libstatagg.a agg/src/agg_curves.o agg/src/agg_font_freetype.o agg/src/agg_image_filters.o agg/src/agg_trans_affine.o agg/src/agg_vcgen_dash.o agg/src/agg_vcgen_stroke.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/homebrew/lib -o ragg.so capture_dev.o init.o jpeg_dev.o png_dev.o ppm_dev.o tiff_dev.o -Lagg -lstatagg -L/opt/homebrew/opt/freetype/lib -L/opt/homebrew/Cellar/libpng/1.6.37/lib -L/opt/homebrew/Cellar/libtiff/4.4.0_1/lib -lfreetype -lz -lbz2 -lpng16 -lz -lpng16 -lz -ltiff -ljpeg -lz -ljpeg -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/00LOCK-ragg/00new/ragg/libs

[...]

stty: stdin isn't a terminal
** testing if installed package keeps a record of temporary installation path
* DONE (ragg)

My question to you all is: Why did attempt 02 fail?

I'm stumped between attempt 02 and 03 because I thought passing INCLUDE_DIR and LIB_DIR was essentially passing along what I added manually to Makevars.


sessionInfo()

R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.4

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

other attached packages:
[1] colorout_1.2-2

loaded via a namespace (and not attached):
[1] compiler_4.2.1 tools_4.2.1
thomasp85 commented 2 years ago

Homebrew on M1 is still a bit of a pain out if the box. I have

CFLAGS=-I/opt/homebrew/include
CPPFLAGS=-I/opt/homebrew/include
CXXFLAGS=-I/opt/homebrew/include
CXX11FLAGS=-I/opt/homebrew/include
LDFLAGS=-L/opt/homebrew/lib

in my ~/.R/Makevars and that seems to take care of it all. I'm not sure why solution 2 didn't work but I assume it might be because it only sets the flags for part of the build step or something