1

I did brew install libgccjit and then I did make configure="--with-native-compilation" and it died with:

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>.
make: *** [Makefile] Error 1

I downloaded the sample program and was finally able to get it to compile with gcc -I/opt/homebrew/include tut01-hello-world.c -o tut01-hello-world -lgccjit -L/opt/homebrew/lib/gcc/12 but then when I try to run it I get:

./tut01-hello-world 
ld: library not found for -lemutls_w
libgccjit.so: error: error invoking gcc driver
NULL result%                

I find libemutls_w down /opt/homebrew/Cellar/gcc/12.2.0/lib/gcc/current/gcc/aarch64-apple-darwin21/12 but I have no idea how to alter the library search path of an executable on macOS. And... I'm not sure that is the right method to address this issue.

I see on here a year ago got it to work for emacs-28 but they used brew. The last time I tried brew's emacs, it didn't build the native macOS version so I've been building it via the tar ball and without native compilation.

I figure the first step is to get the tut01-hello-world to execute and then figure out how to get Emacs to compile and run.

pedz
  • 365
  • 1
  • 12

1 Answers1

2

Sounds like there is maybe something wrong with your compiler chain.

% brew install gcc
% brew install libgccjit
% brew install autoconf
% brew install automake
% git clone https://github.com/emacs-mirror/emacs.git
% cd emacs
% autoreconf -isvf
% ./configure --with-native-compilation
% make -j10
% make check

worksforme. (mostly, 4 test failures from make check)

I haven't seen any verifiable, reproducible benchmarks that demonstrate a tangible benefit to native compilation. In my own light trials when it was new, I found no benefit from it when daily driving Emacs on my 2013 MBP. Everyone's needs are different though.

That being said if you want native binaries, Homebrew does install native binaries for Emacs. brew install emacs installs native binaries from the bottle. brew install --build-from-source emacs builds and installs native binaries. brew install --HEAD emacs builds and installs native binaries. brew install homebrew/cask/emacs (ie. https://emacsformacosx.com/) installs native binaries, but you have to tweak some symlinks in order to use the native ancillary programs (emacsclinet, etags, etc.)

If you have to have native compilation, there are taps available as documented at https://www.emacswiki.org/emacs/GccEmacs.

$ brew tap jimeh/emacs-builds
$ brew install --cask emacs-app-nightly-28

Or:

$ brew tap d12frosted/emacs-plus
$ brew install emacs-plus@28 --with-native-comp

I haven't looked, but I would assume that these taps also provide native binaries.

nega
  • 3,091
  • 15
  • 21
  • I thought I would reinstall gcc, etc. Now `brew install autotools` fails with `Warning: No available formula with the name "autotools". Did you mean atool?` – pedz Dec 02 '22 at 16:08
  • Update: As I mentioned, I thought I would reinstall gcc, libgccjit, and autotools and then try again. I don't know what's up with autotools but when I reinstalled gcc and libgccjit, then did a `make distclean` followed by `make configure="--with-native-compilation"` and `make configure="--with-native-compilation" install` I know have native compiling working. So... probably something with my gcc setup was wonky. (that's a highly technical term!) – pedz Dec 02 '22 at 16:37
  • Well... the saga continues. `(native-comp-available-p)` returns t and emacs tries to native compile but in the log I am seeing the same `ld: library not found for -lemutls_w` issue. Hmmm... So, I got past the configure, make, and make install but Emacs itself is having roughly the same issue. – pedz Dec 02 '22 at 16:47
  • Also, I tried the d12frosted and it failed in the same way. This is most probably something wrong with my setup -- somehow. – pedz Dec 02 '22 at 16:48
  • re: autotools, i've updated my answer. – nega Dec 04 '22 at 20:06
  • re: libemutls_w, it comes with `gcc` – nega Dec 04 '22 at 20:18
  • re: the `d12frosted/emacs-plus` tap. _worksforme_ with building and installing. seems to have some other issues i don't care to investigate. – nega Dec 04 '22 at 20:37
  • I tinkered with this for a few days and could not get consistent results. At this point it is working. One thing, as suggested, is to either uninstall or reinstall gcc and libgccjit. And not just once. I ended up doing those steps two or three times and each time the behavior changed. The Reddit thread I opened on this has others with the same experience. Something appears to be broken other than my setup but at this point it is working for me so I can't investigate further. – pedz Dec 07 '22 at 02:56