Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Having installed the g++ compiler, I thought I might finally be allowed to do some C++ rather than Python on my Pi. Not so though, as my program does not run. It compiles fine, with no errors, and having checked the file explorer it definitely exists. As a Windows man, i have given the executable the .exe extension. This could possibly be my problem, and if it is I would like to know the extension I should give in Linux. If this has no effect and you are starting to think I might be insane, I should say that:

  1. I have never used any other OS apart from Windows.
  2. The .exe file is described by the pi as a DOS/Windows executable, making me think I should give it a different extension.

Any help to my problem is much appreciated.

(My code is here, although I don't think there is anything wrong with it, so if there isn't please tell me or edit it out)

#include <iostream>
using namespace std;

int main()
  cout << "Hello" << endl;
  return 0;
share|improve this question
up vote 7 down vote accepted

It doesn't have to be given a specific extension, you can name it anything - it just has to be executable in order to run:

chmod +x program_name

I checked on my RPI and it looks like executable permissions is set automatically by g++, so you might be missing the './' bit before the program name you are attempting to run if you are in the same directory with the binary:

pi@raspberrypi ~/tmp/c $ cat main.c
#include <iostream>
using namespace std;

int main()
return 0;
pi@raspberrypi ~/tmp/c $ g++ main.c
pi@raspberrypi ~/tmp/c $ ls -la
total 20
drwxr-xr-x 2 pi pi 4096 Feb  6 22:42 .
drwxr-xr-x 4 pi pi 4096 Feb  6 22:38 ..
-rwxr-xr-x 1 pi pi 6836 Feb  6 22:42 a.out
-rw-r--r-- 1 pi pi   88 Feb  6 22:38 main.c
pi@raspberrypi ~/tmp/c $ ./a.out
pi@raspberrypi ~/tmp/c $
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.