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

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

Major mode: Org

Minor modes in effect:
  override-global-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug sendmail org-mobile ffap tmm diary-lib
diary-loaddefs cal-iso face-remap org-agenda org-refile org-clock
mule-util cal-move org-element avl-tree generator ol-eww eww xdg
url-queue mm-url ol-rmail ol-mhe ol-irc ol-info ol-gnus nnselect
gnus-search eieio-opt speedbar ezimage dframe gnus-art mm-uu mml2015
mm-view mml-smime smime dig gnus-sum shr kinsoku svg dom gnus-group
gnus-undo gnus-start gnus-dbus dbus xml gnus-cloud nnimap nnmail
mail-source utf7 netrc nnoo parse-time gnus-spec gnus-int gnus-range
message rfc822 mml mml-sec epa derived mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader gnus-win gnus
nnheader gnus-util rmail rmail-loaddefs rfc2047 rfc2045 ietf-drums
mail-utils mm-util mail-prsvr ol-docview doc-view jka-compr image-mode
exif ol-bibtex ol-bbdb ol-w3m ol-doi org-link-doi dired-aux dired
dired-loaddefs which-key lsp-pyright lsp-mode comp comp-cstr warnings
lsp-protocol yasnippet xref project tree-widget wid-edit spinner pcase
network-stream puny nsm rmc markdown-mode color thingatpt lv inline
imenu ht filenotify f f-shortdoc shortdoc s ewoc epg rfc6068 epg-config
dash compile text-property-search org ob ob-tangle ob-ref ob-lob
ob-table ob-exp org-macro org-footnote org-src ob-comint org-pcomplete
pcomplete comint ansi-color ring org-list org-faces org-entities
noutline outline org-version ob-emacs-lisp ob-core ob-eval org-table
oc-basic bibtex iso8601 time-date ol rx org-keys oc org-compat advice
org-macs org-loaddefs format-spec find-func cal-menu calendar
cal-loaddefs command-log-mode cl-extra help-mode use-package
use-package-ensure use-package-delight use-package-diminish
use-package-bind-key bind-key easy-mmode use-package-core finder-inf
edmacro kmacro wombat-theme info package browse-url url url-proxy
url-privacy url-expand url-methods url-history url-cookie url-domsuf
url-util mailcap url-handlers url-parse auth-source cl-seq eieio
eieio-core cl-macs eieio-loaddefs password-cache json subr-x map
url-vars seq byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib
iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel dos-w32 ls-lisp disp-table
term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice
button loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote threads w32notify w32 lcms2 multi-tty
make-network-process native-compile emacs)

Memory information:
((conses 16 497677 139781)
 (symbols 48 38406 9)
 (strings 32 164117 43025)
 (string-bytes 1 4805171)
 (vectors 16 75523)
 (vector-slots 8 1608377 199020)
 (floats 8 434 411)
 (intervals 56 3060 1085)
 (buffers 992 27))