@Override
	protected CompiledState compile(RunOptions runOptions, GeneratedState generatedState) {
		if (isWindows()) {
			writeVisualStudioProjectFile(runOptions.grammarName, runOptions.lexerName, runOptions.parserName,
					runOptions.useListener, runOptions.useVisitor);
		}

		Exception exception = null;
		try {
			if (!isWindows()) {
				String[] linkCommand = new String[]{"ln", "-s", runtimeLibraryFileName};
				runCommand(linkCommand, getTempDirPath(), "sym link C++ runtime");
			}

			List<String> buildCommand = new ArrayList<>();
			buildCommand.add(getCompilerPath());
			if (isWindows()) {
				buildCommand.add(getTestFileName() + ".vcxproj");
				buildCommand.add("/p:configuration=Release");
				buildCommand.add("/p:platform=x64");
			}
			else {
				buildCommand.add("-std=c++17");
				buildCommand.add("-I");
				buildCommand.add(runtimeSourcePath);
				buildCommand.add("-L.");
				buildCommand.add("-lantlr4-runtime");
				buildCommand.add("-pthread");
				buildCommand.add("-o");
				buildCommand.add(getTestFileName() + ".out");
				buildCommand.add(getTestFileWithExt());
				buildCommand.addAll(generatedState.generatedFiles.stream().map(file -> file.name).collect(Collectors.toList()));
			}

			runCommand(buildCommand.toArray(new String[0]), getTempDirPath(), "build test c++ binary");
		}
		catch (Exception ex) {
			exception = ex;
		}
		return new CompiledState(generatedState, exception);
	}
For my own information on I'm recording what I needed to do to get a unit test to compile and run in C++ on the Mac.
I got a segmentation violation and couldn't figure out how to get information about it, so I turned on debugging
and then figured out lldb enough to create this issue: https://github.com/antlr/antlr4/issues/3845 on a bug.

cd ~/antlr/code/antlr4/runtime/Cpp
cmake . -D CMAKE_OSX_ARCHITECTURES="arm64; x86_64" -DCMAKE_BUILD_TYPE=Debug
make -j 8

In test dir with generated test code:

clang++ -g -std=c++17 -I /Users/parrt/antlr/code/antlr4/runtime/Cpp/runtime/src -L. -lantlr4-runtime *.cpp
./a.out input

$ lldb ./a.out input
(lldb) run
... crash ...
(lldb) thread backtrace
runtime-testsuite/test/org/antlr/v4/test/runtime/cpp/CppRunner.java