I updated my R packages the other day, and not surprisingly, one package failed to compile. This time, it was XML. The error message suggested
configure: error: “libxml not found”, but homebrew suggested I had installed
libxml2 and had it up-to-date.
./configure manually and after some googling, I realized the compiler went to
/usr/bin/xml2-config instead of the homebrew version, and thanks to this thread on StackOverflow, I learned that the compiler would be directed to the correct copy of
libxml2 if I set the environmental variable
Sys.setenv(XML_CONFIG = "/usr/local/Cellar/libxml2/2.9.7/bin/xml2-config") in R console helped me successfully compile
The cause of this problem might be that I did not install Xcode in my computer, which seems to come with a proper version of
libxml2 to replace the one coming with the system, and according to the installation message of
libxml2 from homebrew is keg-only, which means it was not symlinked into
/usr/local, because macOS already provides this software and installing another version in parallel can cause all kinds of trouble. Consequently , the compiler turned to the system copy of
libxml2, causing failed compilation.
Of course, this problem could also be fixed by choosing to install from binary.
R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6Matrix products: default
 en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8attached base packages:
 stats graphics grDevices utils datasets methods baseloaded via a namespace (and not attached):
 compiler_3.4.4 tools_3.4.4 yaml_2.2.0