Same binary for GUI and command line use?

Is there some clean way with JUCE to make the same executable work both as a GUI app and a command line program? Ideally I’d like to avoid doing any GUI initialization/teardown stuff as much as possible, to ensure running the program in the command line mode is as fast as possible.

1 Like

On Mac, a GUI application is an app bundle, but a console application is not. On Windows, you need to link with different flags.

So maybe it’s possible on Linux, but I don’t think it’s something JUCE could work around.

AFAIK, Projucer is a GUI application but you can run it also on the command line for some automated tasks, as shown here: Command line options

If that’s what you want, then you could have a look at its code and see how it’s done

1 Like

Yeah I just realized Projucer is supposed to work like that. @jules Unfortunately, at least on Windows running it from the command line makes it stuck and not return control to cmd.exe. The same thing happens in my app when I use the same code as Projucer does :

setApplicationReturnValue (appReturnCode);
1 Like

IIRC under Windows you have to set a flag in VS to create a GUI application that also takes arguments from the CMD. But the drawback is that when you start such an application in GUI mode, it will always open a CMD window next to it - quite ugly.

An alternative is to compile like you do right now and launch your JUCE application via cygwin. There you can provide command line arguments.

Command line arguments already work for the GUI mode with the stock settings generated by Projucer for the Visual Studio project.

But is it also stuck when launched from cygwin? I never encountered an issue with the Projucer from within cygwin.

That would be quite moot as I don’t want to use or require users to use Cygwin.