--- posix/gawkmisc.c	2025-03-09 19:13:49.000000000 +0800
+++ posix/gawkmisc.c	2025-08-14 20:12:18.000000000 +0800
@@ -35,6 +35,10 @@
 #include <spawn.h>	// for macos
 #endif
 
+#ifdef __APPLE__
+#include <mach-o/dyld.h>
+#endif
+
 const char quote = '\'';
 const char *defpath = DEFPATH;
 const char *deflibpath = DEFLIBPATH;
@@ -341,8 +345,8 @@
 			(void) unsetenv("GAWK_PMA_REINCARNATION");
 	}
 #endif
-#ifdef HAVE__NSGETEXECUTABLEPATH
-	// This code is for macos
+#if defined(HAVE__NSGETEXECUTABLEPATH) && defined(HAVE_SPAWN_H)
+	// This code is for macOS 10.5+
 	if (persist_file != NULL) {
 		const char *cp = getenv("GAWK_PMA_REINCARNATION");
 
