@@ -460,9 +460,10 @@ else if (ch == 1) {
460460 try { macGpp = Runtime .getRuntime ().exec (new String []{"g++" ,"--version" }).waitFor ()==0 ; }
461461 catch (Exception ignored ) {}
462462 String macArch = System .getProperty ("os.arch" ,"" ).contains ("aarch64" ) ? "arm64" : "x64" ;
463- File macLibsDir = new File (System .getProperty ("user.home" ) +
464- "/Library/Application Support/Processing/modes/CppMode/libs/macos-" + macArch );
465- // Also check relative to the mode's own directory
463+ File macLibsDir = (runtimeDir != null )
464+ ? new File (runtimeDir .getParentFile (), "libs/macos-" + macArch )
465+ : new File (System .getProperty ("user.home" ) +
466+ "/Library/Application Support/Processing/modes/CppMode/libs/macos-" + macArch );
466467 boolean hasBundledGlfw = new File (macLibsDir , "libglfw.3.dylib" ).exists ();
467468 boolean hasBundledGlew = new File (macLibsDir , "libGLEW.dylib" ).exists ();
468469 boolean macGlfw = hasBundledGlfw
@@ -636,6 +637,18 @@ public File compile(RunnerListener listener) throws Exception {
636637 if (!dest .exists ())
637638 java .nio .file .Files .copy (font .toPath (), dest .toPath ());
638639 }
640+ // Copy bundled macOS dylibs to sketch folder so the binary finds them at runtime.
641+ if (isMac ) {
642+ String macArch2 = System .getProperty ("os.arch" ,"" ).contains ("aarch64" ) ? "arm64" : "x64" ;
643+ File macLibsDir2 = new File (runtimeDir .getParentFile (), "libs/macos-" + macArch2 );
644+ if (macLibsDir2 .exists ()) {
645+ for (File dylib : macLibsDir2 .listFiles ((d ,n ) -> n .endsWith (".dylib" ))) {
646+ File destDylib = new File (sketch .getFolder (), dylib .getName ());
647+ if (!destDylib .exists ())
648+ java .nio .file .Files .copy (dylib .toPath (), destDylib .toPath ());
649+ }
650+ }
651+ }
639652 listener .statusNotice ("Built: " + binary .getName ());
640653
641654 // Check for required native libraries on all platforms
0 commit comments