r-lib / xml2

Bindings to libxml2
https://xml2.r-lib.org/
Other
219 stars 82 forks source link

Error installing xml2 from source in Apple Silicon (Macbook Air M2) #420

Closed can-taslicukur closed 10 months ago

can-taslicukur commented 11 months ago

This is the error I get when I try to install the package from the terminal (I am not using RStudio).

r$> install.packages("xml2")

Content type 'application/x-gzip' length 272664 bytes (266 KB)
==================================================
downloaded 266 KB

* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
** using staged installation
Found pkg-config cflags and libs!
Using PKG_CFLAGS=-I/opt/homebrew/Cellar/libxml2/2.12.0/include/libxml2
Using PKG_LIBS=-L/opt/homebrew/Cellar/libxml2/2.12.0/lib -lxml2 -lz -L/opt/homebrew/Cellar/icu4c/73.2/lib -licui18n -licuuc -licudata -liconv
** libs
using C compiler: ‘Apple clang version 15.0.0 (clang-1500.0.40.1)’
using C++ compiler: ‘Apple clang version 15.0.0 (clang-1500.0.40.1)’
using SDK: ‘’
clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I/opt/homebrew/Cellar/libxml2/2.12.0/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0  -I/opt/homebrew/include -I/opt/homebrew/opt/libomp/include -Xclang -fopenmp -I/opt/homebrew/opt/libxml2/include    -fPIC  -I/opt/homebrew/include -c connection.cpp -o connection.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I/opt/homebrew/Cellar/libxml2/2.12.0/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0  -I/opt/homebrew/include -I/opt/homebrew/opt/libomp/include -Xclang -fopenmp -I/opt/homebrew/opt/libxml2/include    -fPIC  -I/opt/homebrew/include -c init.c -o init.o
clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I/opt/homebrew/Cellar/libxml2/2.12.0/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0  -I/opt/homebrew/include -I/opt/homebrew/opt/libomp/include -Xclang -fopenmp -I/opt/homebrew/opt/libxml2/include    -fPIC  -I/opt/homebrew/include -c xml2_doc.cpp -o xml2_doc.o
clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I/opt/homebrew/Cellar/libxml2/2.12.0/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0  -I/opt/homebrew/include -I/opt/homebrew/opt/libomp/include -Xclang -fopenmp -I/opt/homebrew/opt/libxml2/include    -fPIC  -I/opt/homebrew/include -c xml2_init.cpp -o xml2_init.o
xml2_init.cpp:46:3: error: no matching function for call to 'xmlSetStructuredErrorFunc'
  xmlSetStructuredErrorFunc(NULL, handleStructuredError);
  ^~~~~~~~~~~~~~~~~~~~~~~~~
/opt/homebrew/Cellar/libxml2/2.12.0/include/libxml2/libxml/xmlerror.h:897:5: note: candidate function not viable: no known conversion from 'void (void *, xmlError *)' (aka 'void (void *, _xmlError *)') to 'xmlStructuredErrorFunc' (aka 'void (*)(void *, const _xmlError *)') for 2nd argument
    xmlSetStructuredErrorFunc   (void *ctx,
    ^
1 error generated.
make: *** [xml2_init.o] Error 1
ERROR: compilation failed for package ‘xml2’
* removing ‘/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/xml2’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/xml2’

The downloaded source packages are in
    ‘/private/var/folders/4z/ml235hpn6ld_6664zy4mb8j00000gn/T/Rtmpnp1LHS/downloaded_packages’
Warning message:
In install.packages("xml2") :
  installation of package ‘xml2’ had non-zero exit status

I have installed libxml2 via Homebrew and applied post-installation instructions. E.g In .R/Makevars I've added:

LDFLAGS += -L/opt/homebrew/opt/libxml2/lib
CPPFLAGS += -I/opt/homebrew/opt/libxml2/include

In .zshrc :

export PATH="/opt/homebrew/opt/libxml2/bin:$PATH"

export PKG_CONFIG_PATH="/opt/homebrew/opt/libxml2/lib/pkgconfig"
hadley commented 10 months ago

Fixed by #417