10

I wish to run Emacs from the latest development version.

I've downloaded the latest Emacs development version from https://savannah.gnu.org/projects/emacs (with git clone -b master git://git.sv.gnu.org/emacs.git), ran autogen.sh as suggested here, then followed the instructions on the screen: after autogen.sh I executed ./autogen.sh git, then ./configure, and finally make (if I run make install instead, I get the same error message as below). All the steps except make seemed to finish successfully.

As for make, it started off well enough, but at some point it stopped with the following error message:

xml.c:23:10: fatal error: 'libxml/tree.h' file not found
#include <libxml/tree.h>
         ^
1 error generated.
make[1]: *** [xml.o] Error 1
make: *** [src] Error 2

My path includes /usr/local/Cellar/libxml2/2.9.4_3/include/libxml2, and this directory in turn contains libxml/tree.h.

How can I fix the problem?


I run macOS Sierra version 10.12.5 .

Drew
  • 75,699
  • 9
  • 109
  • 225
Evan Aad
  • 1,461
  • 1
  • 14
  • 29
  • 1
    Install the `libxml` library (through homebrew)? – Dan Jul 17 '17 at 18:52
  • @Dan: `libxml` is not available via Homebrew. – Evan Aad Jul 17 '17 at 18:59
  • @Dan: However `libxml2` *is* available through Homebrew. Will it do? – Evan Aad Jul 17 '17 at 19:08
  • FWIW, the sequence is `make` (to build the executable and everything else) *and* `make install` (to install the built executable and the rest). – wasamasa Jul 17 '17 at 19:24
  • @wasamasa: I just followed the instructions that appeared on the screen at the end of each step starting with `autogen.sh`. – Evan Aad Jul 17 '17 at 19:27
  • If you are on OSX, why are you not using `./configure --with-ns`? And, why are you not using `make` prior to calling `make install`? – lawlist Jul 17 '17 at 19:34
  • @lawlist: To answer your first question: because the nextstep/INSTALL file says: "On macOS, --with-ns is enabled by default." To answer your second question: I just followed the instructions that appeared on the screen at the end of each step starting with `autogen.sh`, and they didn't mention to run `make`, only `make install`. But I'll run `make` now. – Evan Aad Jul 17 '17 at 19:40
  • @lawlist: `make` results in the same error message as the one I reported in my original post. – Evan Aad Jul 17 '17 at 19:45
  • @lawlist: I should add that my path includes `/usr/local/Cellar/libxml2/2.9.4_3/include/libxml2`, and this directory contains `libxml/tree.h`, so I'm really perplexed. – Evan Aad Jul 17 '17 at 19:47
  • @lawlist: I executed `./config --with-ns` per your suggestion, and then `make`, but I get the same error message. – Evan Aad Jul 17 '17 at 20:01
  • @lawlist Maybe the "2" in the directory name is the culprit? Trying it out with a symlink might help. –  Jul 17 '17 at 20:25
  • @DoMiNeLa10: Per your suggestion I created a symlink: `ln -s /usr/local/Cellar/libxml2/2.9.4_3/include/libxml2 /usr/local/bin/include` and added it to my path before the original entry that the symlink is based on. Alas, I get the same error message. – Evan Aad Jul 17 '17 at 20:51
  • 1
    This looks interesting: https://lists.gnu.org/archive/html/emacs-devel/2015-11/msg01940.html -- I'm not 100% certain it is applicable, but the bottom line of that particular thread is: "*you are missing the command line tools for OSX. Try running `xcode-select --install` from the command line*" – lawlist Jul 17 '17 at 21:50

3 Answers3

27

The accepted answer does not work anymore since libxml2 will be installed inside the XCode directory. The solution is described here:

https://silvae86.github.io/sysadmin/mac/osx/mojave/beta/libxml2/2018/07/05/fixing-missing-headers-for-homebrew-in-mac-osx-mojave/

In short, Apple provides an installer that can put the librairies inside /usr/include. You can copy this installer to your desktop by doing this:

cp /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg ~/Desktop

Once copied, just launch the installer from your Desktop.

carlbolduc
  • 371
  • 4
  • 5
6

The error message described in the question has previously been encountered by other fellow Emacs enthusiasts, and the recommended fix is to install OSX command line tools by running the following from the command line:

xcode-select --install

Here is the link to the Emacs development thread that described the above solution by Daniel Sutton:

http://lists.gnu.org/archive/html/emacs-devel/2015-11/msg01940.html

lawlist
  • 18,826
  • 5
  • 37
  • 118
  • This solution does not work since macOS 10.14 – cjohansson Sep 29 '18 at 14:16
  • You can get the command line tools for 10.14 Mojave from the download site here: https://developer.apple.com/download/more/ Then you'll be able to install the headers as below in @carlbolduc's answer. – Emoses Oct 31 '18 at 17:56
2

I successfully built emacs 26.3 from scratch on macOS 10.15.1 with libxml2 installed using brew without the nonsense in the first two answers. After installing libxml2 and running ./configure, I modified the CFLAGS and CPPFLAGS in emacs-26.3/src/Makefile to terminate with libxml2 instead of include:

CFLAGS = -I/usr/local/opt/libxml2/include/libxml2
CPPFLAGS = -I/usr/local/opt/libxml2/include/libxml2
Erik
  • 121
  • 3
  • Another way to run this is: `CFLAGS="-I/usr/local/opt/libxml2/include/libxml2" CPPFLAGS=-I/usr/local/opt/libxml2/include/libxml2 make install` – rgiar Jan 22 '20 at 03:04
  • 2
    @rgiar I'm old school, I like to keep a record of how it the binary was built so when I come back to recompile a year later I don't have to work this problem again. – Erik Jan 26 '20 at 14:48