'Making Executable C++ file user friendly so someone can run it like an app or software

I wrote a small c++ program to help a family member to automate some of their functions. How can I send it to them and give them ability to run it as if it was an app or at least without them having to run it in terminal (using ./a.out) and/or write command lines?

Basically where they would just click on a file and it will run with the prompts right away.



Solution 1:[1]

You will need to know the runtime environment of your family member's pc. So mainly operating system and cpu architecture. Than porting your application can be achieved by cross-compiling.

For example take a look into the mingw-w64 toolchain to cross-compile to windows (as I assume that you are on linux).

However, I would advise to move to any interpreted languages such as Python or to Java which runs in their own environment that doesn't need cross-compiling to other machines! Depending on your application this can be a lot easier.

Solution 2:[2]

It's hard to know your exact need, maybe all you want is to compile your code to an executable:

c++ main.cpp -o SomeApp

Now, it creates an executable, and you can simply double click it to run.


If you actually want an app with some GUI running on Mac, you can still create one quite easily with Xcode. When you open Xcode, you can select the template macOS->App, and select SwiftUI for interface, and it should automatically create couple files, and have the file named ContentView opened for you.

On the left, you will see a file navigator, and you can drag your a.out file in there to have it included in the project. On the right is the template code:

struct ContentView: View {
    var body: some View {
        Text("Hello World")
        .padding()
    }
}

All you need is to change the line with Text to:

Button("Run")
{
    try! Process.run(URL(fileURLWithPath: "/bin/zsh"), arguments: [
        "-c", Bundle.main.path(forResource: "a", ofType: "out")!
    ])
}

This will create a button that runs a.out through zsh upon clicked: enter image description here


However, this is unlikely to satisfy all your needs. Depends on your exact need, you might need to learn a lot more about SwiftUI and application design in general to create an effective app.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zensayyy
Solution 2 Ranoiaetep