jimeh / build-emacs-for-macos

Somewhat hacky script to automate building of Emac.app on macOS.
484 stars 50 forks source link

Cannot find libgccjit.h #20

Open AllenDang opened 4 years ago

AllenDang commented 4 years ago

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
askurihin commented 4 years ago

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.

AllenDang commented 4 years ago

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

kaz-yos commented 4 years ago

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

carlthuringer commented 3 years ago

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
ghost commented 3 years ago

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.

powellb commented 3 years ago

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.

kaz-yos commented 3 years ago

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

Yevgnen commented 3 years ago

Any new of this?

jimeh commented 3 years ago

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.

gpanders commented 2 years ago

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).

CsBigDataHub commented 2 years ago

@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
jimeh commented 2 years ago

@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.

CsBigDataHub commented 2 years ago

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

jimeh commented 2 years ago

@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.

CsBigDataHub commented 2 years ago

@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

jimeh commented 2 years ago

@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.

CsBigDataHub commented 2 years ago

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.

DJManas commented 2 years ago

@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

jimeh commented 2 years ago

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

DJManas commented 2 years ago

@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. :-)