reddit / emacs

Unable to get Emacs-19 --with-native-compilation for M1 Mac

pedzsanReddit · 2022-12-02 00:06
Edit: the title should be Emacs 29 I cloned the git repo from `https://git.savannah.gnu.org/git/emacs.git` and tried to build it with `make configure="--with-native-compilation"`. It dies when it tested out to see if JIT was working. I followed the instructions, downloaded the sample program, compiled it with `gcc -I/opt/homebrew/include tut01-hello-world.c -o tut01-hello-world -lgccjit -L/opt/homebrew/lib/gcc/12` and then tried to execute the result but I got: ``` ./tut01-hello-world ld: library not found for -lemutls_w libgccjit.so: error: error invoking gcc driver NULL result% ``` I see I have `/opt/homebrew/Cellar/gcc/12.2.0/lib/gcc/current/gcc/aarch64-apple-darwin21/12/libemutls_w.a` and a symbolic link to it at `/opt/homebrew/lib/gcc/current/gcc/aarch64-apple-darwin21/12/libemutls_w.a` but I don't know how to alter the library search path on macOS and I'm not sure if that is the way way to address this issue or if I'm doing something wrong more fundamentally.
HM0880 · 2022-12-02 00:18
Do you really mean v19? Is is that a typo for v29?
pedzsanReddit · 2022-12-02 00:23
V29. Sorry. I'll see if I can fix the header.
colemaker360 · 2022-12-02 01:57
Are you tied to installing Emacs this way? Because if not, I highly recommend using emacs-plus via homebrew: brew tap d12frosted/emacs-plus brew install emacs-plus@28 --with-native-comp
patrixl · 2022-12-02 02:52
You'll need the libgccjit package: brew install libgccjit
pedzsanReddit · 2022-12-02 03:50
I did that. Perhaps I should have mentioned it in my description.
pedzsanReddit · 2022-12-02 03:54
I can try that. I’ve tried some form of brew with emacs and it gave me a version that did not have the native NextStep / Darwin / macOS windowing system. It was only good for running emacs from Terminal. Is the emacs-plus@28 version 28? Or 29? Or master?. The other concern is I’ve hacked on the nsterm.c to add some functionality. While that isn’t a big thing, ultimately I would like to get so I could edit and build the source code.
shaunsingh0207 · 2022-12-02 07:59
> Is the emacs-plus@28 version 28? Or 29? Or master?. The correct command should be `brew install emacs-plus@29 --with-native-comp` > The other concern is I’ve hacked on the nsterm.c to add some functionality. While that isn’t a big thing, ultimately I would like to get so I could edit and build the source code. You can take a look at https://github.com/d12frosted/homebrew-emacs-plus/blob/6f5f8d8d37c2f6a93d2e594c02e767a6dd628c16/Formula/emacs-plus%4029.rb#L29 to look through what other dependencies/tooling you need to compile emacs. You can also fork the homebrew recipe and add your own patches, if thats any easier
tmting · 2022-12-02 11:17
I have a very similar issue under Linux and couldn't for the life of me find a solution. After hundreds of suggested fixes it always ended up with a lot of "library not found for X". Eventually I just gave up on native comp
pedzsanReddit · 2022-12-02 14:54
☹️ It fails in the same way: ``` checking for libgccjit.h... yes configure: error: The installed libgccjit failed to compile and run a test program using the libgccjit library; see config.log for the details of the failure. The test program can be found here: <https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html>. You can try compiling it yourself to investigate the issues. Please report the issue to your distribution if libgccjit was installed through that. You can find the instructions on how to compile and install libgccjit from source on this site: <https://gcc.gnu.org/wiki/JIT>. Do not report this issue to Homebrew/brew or Homebrew/core! These open issues may also help: emacs-plus@29 installs Emacs 30. https://github.com/d12frosted/homebrew-emacs-plus/issues/533 ``` I have emails out to the JIT mailing list.
i_like_peace · 2022-12-02 19:58
I've been running into the same issue for over a month. I can get emacs to compile but on starting emacs it spits the following messages `⛔ Warning (comp): libgccjit.so: error: error invoking gcc driver` `⛔ Warning (comp): /opt/homebrew/Cellar/emacs-plus@29/29.0.50/share/emacs/29.0.50/lisp/emacs-lisp/map.el: Error: Internal native compiler error failed to compile`
treeblahh · 2022-12-02 20:01
I’ve likewise run into issues with this recently, having been able to build from source or install from emacs-plus previously for 29. Lately I’ve been using an older version of emacs main. Similarly, reinstalling libgccjit did not resolve the issue for me. I’m interested in seeing what you come up with here as the solve.
pedzsanReddit · 2022-12-02 20:17
I've done the following at various times: * `brew reinstall gcc` * `brew reinstall libgccjit` * `brew uninstall gcc` followed by a reboot and `brew install gcc` * `brew tap d12frosted/emacs-plus` * `brew install emacs-plus@28 --with-native-comp` I've done the build from the Emacs git repository after checking out the emacs-29 branch as well as trying to compile it via brew as described above. I get different results each time. Right now, it might be working but I'm still poking and prodding. My point here is simply that reinstalling seems to do something. I have no idea what or why.
pedzsanReddit · 2022-12-03 03:06
I am now convinced that this is a random problem. Starting from the git repository on the emacs-29 branch. I have this as `b.sh`: ``` ./configure \ --disable-dependency-tracking \ --disable-silent-rules \ --with-xml2 \ --with-gnutls \ --with-native-compilation \ --without-dbus \ --without-imagemagick \ --with-modules \ --with-rsvg \ --with-ns \ ``` This came roughly from the log files produced when I did `brew install emacs-plus@29 --with-native-comp` but I removed a few items. I then execute `gmake distclean && ./autogen.sh && ./b.sh && gmake && gmake install` Then I move the nextstep/Emacs.app to /Applications, double click it, and watch for smoke. This particular sequence has worked for me three separate builds BUT simply rearranging the order has failed at least once. At one point I could remove the `--disable-dependency-tracking` and it would fail. Add it back in and it would work. But then I did a massive redo and it failed. I kept adding back in the items I had removed and it continued to fail. I added in ALL the remove items and it still failed. That's when I rearranged the order to be like it was (and is shown) and then it works. That doesn't make any sense at all... none of it. So... I bet if I was to redo this build 10 times, it would fail at least a few times meaning that something like a compiler error or uninitialized variable or something very deep down is the bug. It isn't just my environment or how I'm doing things. In the above, when I say "it failed" I am talking about launching the new executable and getting shows below: ``` ⛔ Warning (initialization): An error occurred while loading ‘/Users/pedz/.config/emacs/early-init.el’: Native compiler error: (lambda (arg0 &optional arg1 arg2 arg3 arg4) (let ((f #'load)) (funcall f arg0 arg1 arg2 arg3 arg4))), Compiling /Users/pedz/.config/emacs/eln-cache/29_0_60-b2322fda/subr--trampoline-6c6f6164_load_0.eln... ld: library not found for -lemutls_w libgccjit.so: error: error invoking gcc driver Internal native compiler error: "failed to compile", "/Users/pedz/.config/emacs/eln-cache/29_0_60-b2322fda/subr--trampoline-6c6f6164_load_0.eln", "error invoking gcc driver" Error: native-ice ("failed to compile" "/Users/pedz/.config/emacs/eln-cache/29_0_60-b2322fda/subr--trampoline-6c6f6164_load_0.eln" "error invoking gcc driver") mapbacktrace(#f(compiled-function (evald func args flags) #<bytecode -0xce2157ddc512f81>)) debug-early-backtrace() debug-early(error (native-ice "failed to compile" "/Users/pedz/.config/emacs/eln-cache/29_0_60-b2322fda/subr--trampoline-6c6f6164_load_0.eln" "error invoking gcc driver")) comp--compile-ctxt-to-file("/Users/pedz/.config/emacs/eln-cache/29_0_60-b2322fda/subr--trampoline-6c6f6164_load_0.eln") comp-compile-ctxt-to-file("/Users/pedz/.config/emacs/eln-cache/29_0_60-b2322fda/subr--trampoline-6c6f6164_load_0.eln") comp-final1() eval-buffer(#<buffer *load*> nil "/private/var/folders/54/h1bzk18j3zb9672d80mwtdcc0000gn/T/emacs-int-comp-subr--trampoline-6c6f6164_load_0-jC4hfG.el" nil t) load-with-code-conversion("/private/var/folders/54/h1bzk18j3zb9672d80mwtdcc0000gn/T/emacs-int-comp-subr--trampoline-6c6f6164_load_0-jC4hfG.el" "/private/var/folders/54/h1bzk18j3zb9672d80mwtdcc0000gn/T/emacs-int-comp-subr--trampoline-6c6f6164_load_0-jC4hfG.el" nil t) load("/private/var/folders/54/h1bzk18j3zb9672d80mwtdcc0000gn/T/emacs-int-comp-subr--trampoline-6c6f6164_load_0-jC4hfG.el" nil t) command-line-1(("-l" "/var/folders/54/h1bzk18j3zb9672d80mwtdcc0000gn/T/emacs-int-comp-subr--trampoline-6c6f6164_load_0-jC4hfG.el")) command-line() normal-top-level() ``` This is the latest version of the error and I started getting this after I did the `brew reinstall ...` that I mentioned in another post. Right now it is working. I think I'm going to stop piddling with it and just use what I have.
badmaxton · 2022-12-04 01:08
Emacs plus currently checks out the master branch instead of the emacs-29 branch. To fix it, just: brew edit emacs-plus@29 > on line 74: "master" should be "emacs-29", then save and exit editor ... then do regular brew install emacs-29 Regarding the gcc-jit issue, I've had it as well, yet I repeated the brew install command a number of times. Typically the second or third attempt finds gcc-jit, not sure why :-)
orgtre · 2022-12-04 10:26
I used to have the same error and resolved it like [this](https://github.com/d12frosted/homebrew-emacs-plus/issues/536).