Subject: bug#58318: 28.2; Emacs installed from package won't work with MinGW

From: Eli Zaretskii <[email-masked]>
Date: Thu, 06 Oct 2022 08:44:41 +0300

> From: Bartosz Bubak <[email-masked]>
> Date: Wed, 5 Oct 2022 18:01:00 +0200
> 
> When installing Emacs using the installer (emacs-28.2-installer.exe),
> by default it adds the compiler and libraries (gcc and libgccjit)
> to the ./bin directory without prompting the user for his opinion.
> 
> The problem appears when another compiler is already installed in the
> system, eg. from MinGW. Emacs then tries to use the libraries from PATH
> instead of those installed in its subdirectories:
> 
> Warning (comp): c: /tools/emacs/share/emacs/28.2/lisp/org/org-entities.el:
> Error: Internal native compiler error failed to compile
> Warning (comp): C: \\ ProgramData \\ chocolatey \\ lib \\ mingw \\ tools \\
> install \\ mingw64 \\ bin \\ libgccjit-0.dll: error: error invoking gcc
> driver
> 
> When I tried to find a solution to the problem, I found something like
> this:
> 
> M-: (executable-find "gcc") RET
> "c:/ProgramData/chocolatey/bin/gcc.exe
> M-: (executable-find "as") RET
> "c:/ProgramData/chocolatey/bin/as.exe"
> etc, etc
> 
> But  should be:
> C:\Program Files\Emacs\emacs-28.2\bin\gcc.exe
> C:\Program Files\Emacs\emacs-28.2\bin\as.exe
> 
> The only solution I have found so far is to uninstall the "global"
> MinGW, then emacs uses the embedded libraries and everything is fine.
> 
> In GNU Emacs 28.2 (build 2, x86_64-w64-mingw32)
>  of 2022-09-13 built on AVALON
> Windowing system distributor 'Microsoft Corp.', version 10.0.22000
> System Description: Microsoft Windows 10 Pro (v10.0.2009.22000.978)
> 
> Configured using:
>  'configure --with-modules --without-dbus --with-native-compilation
>  --without-compress-install CFLAGS=-O2'
> 
> Configured features:
> ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
> NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
> XPM ZLIB
> 
> (NATIVE_COMP present but libgccjit not available)
> 
> Important settings:
>   value of $LANG: PLK
>   locale-coding-system: cp1250

Corwin, are you reading this?

I admit I don't have a clear idea of why the problem happens.  Is the
libgccjit and/or GCC and/or Binutils distributed by chocolatey somehow
incompatible with the ones you include in the installer?  Because if
they are compatible, just removing the GCC/Binutils stuff bundled with
the Emacs installer should have solved the issue (and then providing
an option in the installer not to install the bundled GCC would be a
way towards solving this).  And yet the OP seems to say (AFAIU) that
this didn't help, and only uninstalling the chocolatey GCC/Binutils
did.  We cannot possibly ask users to uninstall their existing
development environment when installing Emacs.

I think someone should try installing the chocolatey distribution and
see whether the binaries from the GNU FTP site can work with its
libgccjit.  Because I'm not sure I understand what happens in this
case, even though I asked several times.  If indeed there's
incompatibility, I'd be interested to know why (I have no idea how
chocolatey builds its GCC).  If that is not solvable, we should
probably say that people with chocolatey installation should not
install Emacs binaries with native-compilation enabled.