Hi All,

I am learning to write c++ code, all is going well so far, I am currently compiling my applications with the g++ command in terminal, this creates my executable file no problems however at the moment I can only start my applications from terminal using ./Whatever.

What do I have to do to be able to start my applications by just double clicking the icon like I would do to start firefox or calc.

All I have been writing so far are console applications is this the reason, I would have thaught that some how I could double click the icon and a terminal window would open and my program would run????

Thanks very much

John

I assume you are using Linux?

The program will run in Linux if you double-click it, but you may not get a console window. For example:

#include <iostream>
#include <fstream>
using namespace std;

int main ()
{
    ofstream outs;
    outs.open ("HelloWorld.txt");
    outs << "Hello World";
    outs.close ();
    cout << "Hello World";
    cin.get ();
    return 0;
}

Double click the executable and you should see the file "HelloWorld.txt" appear. The contents will be "Hello World" so you know the program has run. When I did this, I got no console window with "Hello World". To get the console window, I made a shell script:

#! /bin/bash
./HelloWorld

where HelloWorld is the name of the executable.

Make the shell script executable if it is not already. Double click it and in Fedora 10, it asks whether you want to "Run In Terminal". Answer yes and you'll see "Hello World" in a terminal window.

Why this is or if there is any way that you can directly double click the executable program is something I do not know, but this works, at least in Fedora 10.

Edited 6 Years Ago by VernonDozier: n/a

I assume you are using Linux?

The program will run in Linux if you double-click it, but you may not get a console window. For example:

#include <iostream>
#include <fstream>
using namespace std;

int main ()
{
    ofstream outs;
    outs.open ("HelloWorld.txt");
    outs << "Hello World";
    outs.close ();
    cout << "Hello World";
    cin.get ();
    return 0;
}

Double click the executable and you should see the file "HelloWorld.txt" appear. The contents will be "Hello World" so you know the program has run. When I did this, I got no console window with "Hello World". To get the console window, I made a shell script:

#! /bin/bash
./HelloWorld

where HelloWorld is the name of the executable.

Make the shell script executable if it is not already. Double click it and in Fedora 10, it asks whether you want to "Run In Terminal". Answer yes and you'll see "Hello World" in a terminal window.

Why this is or if there is any way that you can directly double click the executable program is something I do not know, but this works, at least in Fedora 10.

Thanks for the reply, yes I am using Linux, I am using Mandriva 2010, I will have a play with the code and see what I can do.

Thanks very much.

John

This article has been dead for over six months. Start a new discussion instead.