Skip to content

Commit cf227c9

Browse files
committed
Windows: static link libgcc and libstdc++ to eliminate DLL version dependency
1 parent f6ed1d5 commit cf227c9

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

mode/CppMode.jar

-2 Bytes
Binary file not shown.

src/java/CppBuild.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ private boolean windowsLibsNowPresent(java.util.List<String> searchDirs, String[
654654

655655
private void checkWindowsDLLs(RunnerListener listener, File binary) throws Exception {
656656
String[] allDlls = { "glfw3.dll", "glew32.dll",
657-
"libgcc_s_seh-1.dll", "libstdc++-6.dll", "libwinpthread-1.dll", "libssp-0.dll" };
657+
"libgcc_s_seh-1.dll", "libwinpthread-1.dll", "libssp-0.dll" };
658658
String[] required = { "glfw3.dll", "glew32.dll" };
659659

660660
// Bundled DLLs are in libs/windows-x64 -- copy them next to the binary
@@ -3183,16 +3183,18 @@ else if (!cmd.contains(defaultsCpp.getAbsolutePath()))
31833183
if (stbTTF.exists()) cmd.add("-DPROCESSING_HAS_STB_TRUETYPE");
31843184

31853185
if (win) {
3186-
// Link against bundled import libs in libs/windows-x64/
3187-
File winLibs = new File(runtimeDir.getParentFile(), "libs/windows-x64");
3188-
if (winLibs.exists()) cmd.add("-L" + winLibs.getAbsolutePath());
3189-
// Also add WinLibs portable gcc bin dir for runtime DLLs
3186+
// Link against import libs: WinLibs first, then bundled, then MSYS2
31903187
File portableBin = InstallWizard.getPortableGccDir();
31913188
if (portableBin.exists()) cmd.add("-L" + portableBin.getAbsolutePath());
3189+
// Add sketch folder to -L so DLLs copied there can be linked directly
3190+
cmd.add("-L" + sketch.getFolder().getAbsolutePath());
3191+
File winLibs = new File(runtimeDir.getParentFile(), "libs/windows-x64");
3192+
if (winLibs.exists()) cmd.add("-L" + winLibs.getAbsolutePath());
31923193
Collections.addAll(cmd,
31933194
"-lglfw3", "-lglew32", "-lopengl32", "-lglu32",
31943195
"-lcomdlg32", "-lshell32", "-lole32", "-luuid",
3195-
"-mwindows", "-pthread", "-D_USE_MATH_DEFINES");
3196+
"-mwindows", "-pthread", "-D_USE_MATH_DEFINES",
3197+
"-static-libgcc", "-static-libstdc++");
31963198
} else if (mac) {
31973199
// macOS: prefer bundled dylibs shipped with the mode (libs/macos)
31983200
// universal dylibs work on both arm64 and x64.

0 commit comments

Comments
 (0)