1

Hi I have the following program. When I compile on the terminal gcc main.c I do get an executable named a.out. However if I type a.out in the terminal I get the following message: a.out: command not found

Any ideas on what I might be doing wrong?

#include <stdio.h> #include <stdlib.h> #define PROMPT "print something" /* * */ int main() { printf("CS-xxx Assignment x, xxxxx\n"); printf(PROMPT); return (EXIT_SUCCESS); } 
1
  • This question may be useful for many new developers, but it's title needs to be changed, as it's not really a compilation problem. maybe 'How to run a program in Unix/Linux after compilation?' Commented Sep 10, 2009 at 23:21

7 Answers 7

13

Assuming you use a Unix-based system, usually "." is not in the path: So, try ./a.out

Sign up to request clarification or add additional context in comments.

Comments

5

Try using

./a.out 

Most Linux systems will not look in the current directory for executables, so you need to tell it to look in the current directory.

Comments

1

You might not have "." (current directory) in your PATH environment variable.

Try running "./a.out" or add "." to your PATH.

2 Comments

But bear in mind that "." is not in the $PATH for security reasons, so unless you really need to - avoid to add it to your $PATH.
I'm with E Eominique: don't do it. But if you must, always put '.' it at the end of the search path.
1

Use

./a.out

You must run program specifying current directory.

Comments

0

Just type ./a.out and things should work. The issue is without ./ the shell thinks you are typing in a command.

1 Comment

He is typing in a command. The shell just doesn't find one of that name on $PATH.
0

Must run all the c, c++, shell programs by specifying directory path under unix family. the symbol ./ should specify the current directory.

Examples: ./kernel (kernel elf is in current directory) ../kernel (kernel elf is in parent directory of current directory) childdir/kernel (kernel elf is in child directory of current directory)

Comments

0

Use ./a.out now you are able to execute your executable file. This ./ is basically denotes find in current directory.

I think now you get what you have to do.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.