build-emacs-for-macos icon indicating copy to clipboard operation
build-emacs-for-macos copied to clipboard

Cannot find libgccjit.h

Open AllenDang opened this issue 3 years ago • 20 comments

Here is my step to repo this issue:

git clone https://github.com/jimeh/build-emacs-for-macos
cd build-emacs-for-macos
brew bundle
./build-emacs-for-macos feature/native-comp

Here is the error message

checking for gcc_jit_context_acquire in -lgccjit... yes
checking libgccjit.h usability... no
checking libgccjit.h presence... no
checking for libgccjit.h... no
configure: error: elisp native compiler requested but libgccjit header files were
not found.

I checked that libgccjit is already installed by homebrew, here is the result of brew info libgccjit.

❯ brew info libgccjit
libgccjit: stable 10.2.0 (bottled), HEAD
JIT library for the GNU compiler collection
https://gcc.gnu.org/
/usr/local/Cellar/libgccjit/10.2.0 (14 files, 34.6MB) *
  Poured from bottle on 2020-11-18 at 13:10:54
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/libgccjit.rb
License: GPL-3.0-or-later with GCC-exception-3.1
==> Dependencies
Required: gmp ✔, isl ✔, libmpc ✔, mpfr ✔
==> Options
--HEAD
	Install HEAD version

AllenDang avatar Nov 18 '20 05:11 AllenDang

I have a slightly different problem, libgccjit.h is present, but smoke test fails:

checking libgccjit.h presence... yes
checking for libgccjit.h... yes
configure: error: Installed libgccjit has failed passing the smoke test.
You can verify it yourself compiling:
<https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html>.
Please report the issue to your distribution if libgccjit was installed through
that.
Here instructions on how to compile and install libgccjit from source:
<https://gcc.gnu.org/wiki/JIT>.

I tried setting CFLAGS, LDFLAGS, LIBRARY_PATH, CC but it didn't help:

export CFLAGS="-I/usr/local/Cellar/libgccjit/10.2.0/include"
export LDFLAGS="-L/usr/local/Cellar/libgccjit/10.2.0/lib/gcc/10 -I/usr/local/Cellar/libgccjit/10.2.0/include"
export LIBRARY_PATH="/usr/local/Cellar/libgccjit/10.2.0/lib/gcc/10:${LIBRARY_PATH:-}"
export CC=/usr/local/bin/gcc-10

OS: Big Sur 11.0.1 (20B28)

Any help will be appreciated.

askurihin avatar Nov 21 '20 14:11 askurihin

I had to change build-emacs-for-macos, add following line to ENV['CFLAGS'] to build. "-I#{libgccjit_dir}/include" And I got two warning messages

checking libgccjit.h presence... no
configure: WARNING: libgccjit.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: libgccjit.h: proceeding with the compiler's result

But after built, launch emacs.app gives me error

startup--load-user-init-file: Cannot open load file: No such file or directory, warnings

And this error message pops up when I'm trying to quit emacs

setq: Cannot open load file: No such file or directory, cl-seq

Update: Problem sovled. I had to delete doom completely and reinstall. Now everything works fine. :P

AllenDang avatar Nov 26 '20 07:11 AllenDang

I solved the smoke test issue by reinstalling the Xcode Command Line Tool. Running the smoke test may provide informative error messages.

kaz-yos avatar Dec 01 '20 00:12 kaz-yos

I solved the smoke test issue by reinstalling the Xcode Command Line Tool. Running the smoke test may provide informative error messages.

Tried this, but didn't help.

I solved the smoke test by reinstalling libgccjit from source. I first tried to use the HEAD but that fails.

brew install -s libgccjit
...
brew test libgccjit

carlthuringer avatar Dec 18 '20 14:12 carlthuringer

If you have upgraded from Catalina to Big Sur, then you should reinstall gcc and libgccjit. Reinstalling them both did the trick for me. Also, completely remove CLT and install the dmg from the developer.apple.com.

ghost avatar Dec 20 '20 16:12 ghost

Upgrading to Macos 11.1 and Xcode 12.3 seems to have broken everything for me. I can no longer link properly against the libgccjit. Using the libgccjit tutorial01 as my smoke test, it used to work fine (and, as such, emacs worked). I compile with:

gcc-10 -I/usr/local//Cellar/libgccjit/10.2.0/include tut01.c -o a.out -L/usr/local/lib/gcc/10/ -lgccjit

which works without error. Running the executable results in:

    x86_64-apple-darwin20-gcc-10.2.0: warning: couldn't understand version 11.0
    ld: library not found for -ldylib1.o
    collect2: error: ld returned 1 exit status
    libgccjit.so: error: error invoking gcc driver
    NULL result%

Updating build-emacs-for-macos and trying to recompile results in the same errors. Unfortunately, my previously compiled emacs (from MacOS 11.0) no longer performs native compilation because of the "Cannot find -lSystem" error that is corrected in the latest build-emacs-for-macos.

Anyone else having these woes?

EDIT: I forgot to mention that I have upgraded (even removed and reinstalled) the brew packages.

powellb avatar Dec 28 '20 20:12 powellb

This may help: https://github.com/Homebrew/homebrew-core/pull/60338#issuecomment-751265538

kaz-yos avatar Dec 28 '20 21:12 kaz-yos

Any new of this?

Yevgnen avatar Feb 20 '21 03:02 Yevgnen

Apologies for my silence on this issue. I've yet been unable to reproduce it myself on either Catalina or Big Sur.

However I've just pushed an update that adds libgccjit's include directory to CFLAGS, as @AllenDang mentioned that worked for him in hopes it might improve things for others.

Also existing CFLAGS and LDFLAGS environment variables you set before running the build script will be taken into account now. Previously the script set them to explicit values and ignored any existing values.

Though overall it's sounding like this might be more a homebrew/gcc/libgccjit issue, as re-installing the homebrew packages seems to resolve the issue for some people.

jimeh avatar Feb 21 '21 15:02 jimeh

I found this issue from an online search, and can verify that brew reinstall gcc fixed the issue for me (I recently upgraded from Catalina to Monterrey).

gpanders avatar Apr 07 '22 14:04 gpanders

@jimeh

Any insights in to this?

Here are the exported variables.

image

ran

brew reinstall libgccjit --build-from-source --force
 brew reinstall gcc --build-from-source --force

still facing this error

checking for dbus_type_is_valid... yes
checking for dbus_validate_bus_name... yes
checking for dbus_validate_path... yes
checking for dbus_validate_interface... yes
checking for dbus_validate_member... yes
checking for lgetfilecon in -lselinux... no
checking for gnutls >= 2.12.2... yes
checking for libsystemd >= 222... no
checking for jansson >= 2.7... yes
checking for sys/inotify.h... no
checking for libkqueue... no
checking for library containing kqueue... none required
checking for jpeglib 6b or later... -ljpeg
checking for lcms2... yes
checking for library containing inflateEnd... -lz
checking for dladdr... yes
checking for dlfunc... no
dirname: missing operand
Try 'dirname --help' for more information.
checking for gcc_jit_context_acquire in -lgccjit... no
configure: error: ELisp native compiler was requested, but libgccjit was not found.
Please try installing libgccjit or a similar package.
If you are sure you want Emacs be compiled without ELisp native compiler,
pass the --without-native-compilation option to configure.
ERROR: Exit code: 1

CsBigDataHub avatar Apr 30 '22 23:04 CsBigDataHub

@CsBigDataHub That error is weird. It seems like a invalid argument was passed to the dirname command.

I'm not super familiar with the exact code in the configure script used to locate libgccjit. But I'll try and dig into it a bit tomorrow.

jimeh avatar Apr 30 '22 23:04 jimeh

Thanks @jimeh ,

I think this is an issue with this script - https://github.com/jimeh/build-emacs-for-macos/blob/master/helper/emacs-cli.bash

I think this will help - https://unix.stackexchange.com/questions/30446/strange-behavior-in-dirname-readlink-f-0

CsBigDataHub avatar May 01 '22 22:05 CsBigDataHub

@CsBigDataHub That script should be irrelevant to your issue. It is added to the built Emacs.app after the normal build process has completed, while in your case you're not even getting through the configure part of Emacs' Norma build process.

jimeh avatar May 01 '22 22:05 jimeh

@CsBigDataHub That script should be irrelevant to your issue. It is added to the built Emacs.app after the normal build process has completed, while in your case you're not even getting through the configure part of Emacs' Norma build process.

Got it thanks

CsBigDataHub avatar May 01 '22 22:05 CsBigDataHub

@CsBigDataHub I think your issue might have been temporary and caused by libgccjit renaming libgccjit.so to libgccjit.dylib in version 11.3.0. From what I can gather, Emacs' configure script would have been failing with a error similar to yours until this commit was added to master:

https://github.com/emacs-mirror/emacs/commit/faa29fa2c9e9d5a5d7544a1a39b2a89cf57a8439

So in short, if you try with latest master now, it should hopefully work.

jimeh avatar May 02 '22 12:05 jimeh

Thanks @jimeh , Since I still wanted to use emacs-28.1 I have updated this line in `./build-emacs-for-macos/sources/emacs-mirror-emacs-5a223c7/configure.ac' at https://github.com/emacs-mirror/emacs/blob/5a223c7f2ef4c31abbd46367b6ea83cd19d30aa7/configure.ac#L3847 .

Build was successful. Once again thanks for looking in to this.

CsBigDataHub avatar May 02 '22 13:05 CsBigDataHub

@jimeh Great thanks.

cd /usr/local/Cellar/libgccjit/11.3.0/lib/gcc/11
ln -s libgccjit.dylib libgccjit.so

Solved my issue. For ./build-emacs-for-macos --native-comp --native-march emacs-28

DJManas avatar May 10 '22 16:05 DJManas

@DJManas thats not a bad idea. I'll try and have the build script do that automatically when I have some free time :)

jimeh avatar May 10 '22 18:05 jimeh

@DJManas thats not a bad idea. I'll try and have the build script do that automatically when I have some free time :)

Great, thanks. :-)

DJManas avatar May 11 '22 07:05 DJManas