yrazlik
yrazlik

Reputation: 10777

How to execute a program in linux after compiling it?

I am compiling a C code in linux with the following command:

gcc -o myprogram myprogram.c

If I hadn't given a name to it, I could have simply written the command ./a.out to execute it. But now, to execute the program I just write "myprogram" to the command line, but it says "command not found". What can I do to execute it?

Upvotes: 4

Views: 32916

Answers (2)

Bruno
Bruno

Reputation: 122649

It's possible that the current directory (".") isn't on your PATH. (You can check this by typing echo $PATH, this is a list of directories delimited with" :". "." should be in the list if you want to run something in the current directory.)

If the current directory isn't on your PATH, you'll need to type ./myprogram (or whatever the correct path is).

Upvotes: 4

user529758
user529758

Reputation:

./myprogram

should do the trick.

(But really... have you looked at the contents of the directory after compiling the program "without name"? Or do you think ./a.out is a magic sequence Bash recognizes?)

Upvotes: 2

Related Questions