Subject: Re: bug#55741: Getting an error when running the Emacs 28.1 binary that I built from source

From: Eli Zaretskii <[email-masked]>
Date: Thu, 02 Jun 2022 10:02:42 +0300

> Date: Tue, 31 May 2022 19:50:42 +0000
> From: cinnaroll45 <[email-masked]>
> Cc: [email-masked]
> 
> > The --bindir switch could be the problem: as you see from the error
> > message, Emacs 28.1 thinks its binary is in /home/user/emacs/bin, not
> > in /home/user/bin. So my suggestion is to reconfigure without the
> > --bindir switch, as I don't think this is currently supported for the
> > build with native-compilation.
> 
> Removing the --bindir switch solved the issue for me. Everything gets installed to the
> expected location and the Emacs binary runs.
> 
> > And in addition, please show the full absolute file name of the
> > emacs.pdmp file, so we could know in which directory it is installed on your system.
> 
> The location of the pdmp file was:
> /home/user/emacs/libexec/emacs/28.1/x86_64-pc-linux-gnu/emacs.pdmp
> 
> > Can you show the full absolute file name of the file window-0d1b8b93-7ef4271a.eln with
> > this installation?  In which directory is it installed by "make install"?
> 
> I couldn't expand the absolute location of `window-0d1b8b93-7ef4271a.eln`. The error message seemed to
> indicate that it was looking for it under the directory where `emacs.pdmp` is, however there were no
> directories present in that path. Just the pdmp file and three other binaries.
> 
> Thank you for helping out!

Thanks, but could you please test a possible fix for the original
problem?  I'd like us to keep supporting the --bindir configure-time
option, as we didn't intend dropping its support in Emacs 28.

So could you please re-configure Emacs 28.1 with your original
options, including the separate --bindir, and then rebuild it with the
patch below, install it by "make install", and see if Emacs now starts
up correctly?  If it doesn't start (or doesn't build), please show any
error messages you see.  TIA.

diff --git a/src/emacs.c b/src/emacs.c
index ccc0dd2..0a90b09 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -940,20 +940,24 @@ load_pdump (int argc, char **argv)
   sprintf (dump_file, "%s%c%s%s",
            path_exec, DIRECTORY_SEP, argv0_base, suffix);
 #if !defined (NS_SELF_CONTAINED)
-  /* Assume the Emacs binary lives in a sibling directory as set up by
-     the default installation configuration.  */
-  const char *go_up = "../../../../bin/";
-  needed += (strip_suffix ? strlen (strip_suffix) : 0)
-    - strlen (suffix) + strlen (go_up);
-  if (exec_bufsize < needed)
-    {
-      xfree (emacs_executable);
-      emacs_executable = xpalloc (NULL, &exec_bufsize, needed - exec_bufsize,
-				  -1, 1);
-    }
-  sprintf (emacs_executable, "%s%c%s%s%s",
-	   path_exec, DIRECTORY_SEP, go_up, argv0_base,
-	   strip_suffix ? strip_suffix : "");
+  if (!(emacs_executable && *emacs_executable))
+    {
+      /* If we didn't find the Emacs binary, assume that it lives in a
+	 sibling directory as set up by the default installation
+	 configuration.  */
+      const char *go_up = "../../../../bin/";
+      needed += (strip_suffix ? strlen (strip_suffix) : 0)
+	- strlen (suffix) + strlen (go_up);
+      if (exec_bufsize < needed)
+	{
+	  xfree (emacs_executable);
+	  emacs_executable = xpalloc (NULL, &exec_bufsize,
+				      needed - exec_bufsize, -1, 1);
+	}
+      sprintf (emacs_executable, "%s%c%s%s%s",
+	       path_exec, DIRECTORY_SEP, go_up, argv0_base,
+	       strip_suffix ? strip_suffix : "");
+    }
 #endif
   result = pdumper_load (dump_file, emacs_executable);