Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a program in linux after compiling it?

Tags:

c

linux

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?

like image 950
yrazlik Avatar asked Oct 19 '25 01:10

yrazlik


2 Answers

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).

like image 94
Bruno Avatar answered Oct 20 '25 13:10

Bruno


./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?)


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!