0

I've built Emacs from source on MacOS (12.4, M1) and it works when I execute the binary from /usr/local/bin/emacs, but I can't open Emacs from Emacs.app.

For example:

mv ~/emacs/nextstep/Emacs.app /Applications/Emacs.app

I then try to open Emacs.app from my Applications folder, but it silently fails.

Here's how I'm building Emacs from source:

$ ./autogen.sh

$ ./configure --with-native-compilation \
              --with-ns \
              --disable-silent-rules \
              --disable-ns-self-contained

$ make

$ make install

I can open emacs no problem when I use the installed binary in /usr/local/bin:

$ emacs & # good to go!

Here's what I get when trying to run the Emacs binary within Emacs.app:

$ /Applications/Emacs.app/Contents/MacOS/Emacs

Error using execdir /Applications/Emacs.app/Contents/MacOS/:
emacs: dlopen(/Applications/Emacs.app/Contents/MacOS/../native-lisp/29.0.50-6a95966f/preloaded/window-0d1b8b93-33d07edc.eln, 0x0001): tried: '/Applications/Emacs.app/Contents/MacOS/../native-lisp/29.0.50-6a95966f/preloaded/window-0d1b8b93-33d07edc.eln' (no such file)

edit

I found perhaps a related issue: homebrew-emacs-plus#392 and it's associated fix. Perhaps the problem is related to the emacs/native-lisp directory not being present in the Emacs.app package.

I tried to resolve by simply moving the native-lisp/ directory into my Emacs.app package:

$ mv ~/emacs/nextstep/Emacs.app /Applications/Emacs.app
$ mv ~/emacs/native-lisp/ /Applications/Emacs.app/Contents/

This appeared to fix the issue, in that I was able to use Emacs.app and launch the program. However, after launching the program this way there are a suite of warnings that show up related to native compilation:

libgccjit.so: error: error invoking gcc driver

I think simply moving the native-lisp/ folder into the app package was probably not sufficient.

2
  • Try at the command line: open /Applications/Emacs.app ; it may print an error that could help figure this out.
    – amitp
    Oct 23, 2022 at 16:33
  • No additional output from open ..., but I did try /Applications/Emacs.app/Contents/MacOS/Emacs to run the binary included within the App folder and got "Error using execdir". I added the full output to the original post.
    – treeblah
    Oct 23, 2022 at 17:56

2 Answers 2

1

Do not move the Emacs.app to Applications folder; instead use a symlink: ln -s /opt/homebrew/opt/emacs-plus@28/Emacs.app /Applications - (modify this one for your path). Note brew also compile from sources and install on your computer. It uses several patches to finalise the installation.

Edit: You can drag and drop it on doc, no need to write symlink. Edit 2: I added the following lines in my .zshrc

export PATH="/opt/homebrew/Cellar/emacs-plus@28/28.2/bin:$PATH"
alias ec="/opt/homebrew/Cellar/emacs-plus@28/28.2/bin/emacsclient"
alias te="/opt/homebrew/Cellar/emacs-plus@28/28.2/bin/emacs -nw"
3
  • This works if I don't pass the --disable-ns-self-contained flag, but continues to fail with that flag present. Maybe I just need to stop passing that flag if I want to use Emacs.app, and add emacs/src/ and emacs/lib-src/ to my PATH so I have access to emacs/emacscilent from the command line?
    – treeblah
    Oct 26, 2022 at 1:16
  • See the Edit #2.
    – Ian
    Oct 26, 2022 at 8:11
  • Even with this strategy, the self-contained Emacs.app continues to have issues. It launches, but emits a ton of "libgccjit.so: error: error invoking gcc driver" warnings into my Messages buffer. Meanwhile, src/emacs works totally fine. I have libgccjit installed via brew, so I imagine there's something going on with the Emacs.app paths.
    – treeblah
    Oct 27, 2022 at 0:42
0

Here's what ended up resolving this problem for me:

  1. Remove --disable-ns-self-contained from the configure script, to ensure that all build artifacts are copied into the Emacs.app package.
./configure --with-native-compilation \
            --with-ns \
            --disable-silent-rules
  1. Re-run the Emacs build.
  2. Symlink nextstep/Emacs.app instead of moving it (though I think since self-contained is enabled, you can really just move this to Applications so this may be unnecessary).
  3. Add emacs/src/ and emacs/lib-src to your PATH so you can still run emacs via CLI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.