Skip to content

Commit a5e34fd

Browse files
committed
Detect old g++ and show clear error
1 parent bb196ed commit a5e34fd

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/java/CppBuild.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,12 @@ public File compile(RunnerListener listener) throws Exception {
508508
File binary = new File(buildDir, sketch.getName() + ext);
509509
String gpp = findGpp(isWindows);
510510

511+
int gppVer = gppMajorVersion(gpp);
512+
if (gppVer > 0 && gppVer < 7) {
513+
listener.statusError("g++ " + gppVer + " is too old. CppMode requires GCC 7+ for C++17.");
514+
throw new Exception("g++ too old: " + gppVer);
515+
}
516+
511517
String stdOverride = (listener instanceof CppEditor ce) ? ce.getSelectedCppStd() : null;
512518
List<String> cmd = buildCommand(gpp, sketchSrc, binary, isWindows, isMac, stdOverride);
513519
listener.statusNotice("$ " + String.join(" ", cmd));
@@ -3342,6 +3348,19 @@ private String preprocessMacros(String code) {
33423348
}
33433349
}
33443350

3351+
/** Returns the major version of the given g++ binary, or 0 if unknown. */
3352+
static int gppMajorVersion(String gpp) {
3353+
try {
3354+
Process proc = new ProcessBuilder(gpp, "--version").redirectErrorStream(true).start();
3355+
String out = new String(proc.getInputStream().readAllBytes());
3356+
proc.waitFor();
3357+
// Output: "g++ (GCC) 13.2.0 ..." or "Apple clang version 15.0.0 ..."
3358+
java.util.regex.Matcher m = java.util.regex.Pattern.compile("(\d+)\.\d+\.\d+").matcher(out);
3359+
if (m.find()) return Integer.parseInt(m.group(1));
3360+
} catch (Exception ignored) {}
3361+
return 0;
3362+
}
3363+
33453364
private String findGpp(boolean win) {
33463365
if (win) {
33473366
for (String p : new String[]{

0 commit comments

Comments
 (0)