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?
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).
./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?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With