~ $ a.out

a.out: command not found

Why does a.out not run?

It appears there is a gcc because

~ $ gcc

gcc: no input files

Following instructions I found here:

http://www.physics.drexel.edu/courses/Comp_Phys/General/C_basics/#first

I created a file called hello.c

#include <stdio.h>
void main ()
{
    printf("\n");
    printf("Hello World");
    printf("\n");
}

Back in the terminal I typed:

~ $ gcc hello.c

~ $ ls

a.out hello.c

~ $ a.out

a.out: command not found

I looked at the properties of a.out and it does have a checkmark for executable. So what am I missing? Is there some guru out there that can help me get off the ground with gcc? Thanks for reading.

1 answers, votes, 3503 views
hugs's picture
asked by hugs
3 years 18 weeks ago



1 Answers

Answer

You cannot simply type the name of the executable file 'a.out', which will return:

a.out: command not found

You are required to prefix the executable file with a path in order for it to run (don't ask me why).

~ $ ./a.out

or

~ $ /path/to/directory/a.out

Then you get:

Hello World

It took me a couple of hours to find this out. I hope this will save others some time. It's really cool to know that a functioning gcc compiler is already included in Ubuntu.

gcc page: http://gcc.gnu.org

hugs's picture
answer by hugs
3 years 18 weeks ago
  • A more convenient solution is to include the current directory in your PATH:

    PATH=.:$PATH

    - Visitor 3 years 18 weeks ago
  • linux goes by the PATH no matter where you are to keep things simple. So, if you want to execute a command in current directory you have explicitly say
    ./command or /path/command

    - Visitor 3 years 18 weeks ago
  • Have a question or want to discuss an idea about Chromecast? checkout chromecast forums

    Ubuntu 13.04 released!

    Ubuntu 13.04 code named Raring Ringtail is released download ubuntu 13.04. Download while it's hot!!

    View in your own language!

    Stay Connected

    Ubun2.com on Facebook Ubun2.com on Twitter RSS Feeds

    Poll

    Favorite desktop environment?: