4

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?

2
  • 3
    Current working directory is not on the path. Commented Feb 25, 2013 at 17:30
  • You really should take the habit of compiling with gcc -Wall -g myprogram.c -o myprogram then learn how to use make with your Makefile. You'll also need to learn how to use the gdb debugger. Commented Feb 25, 2013 at 18:50

2 Answers 2

4

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

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

Comments

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

3 Comments

@bigO - FYI, the answer above works assuming that you're in the same directory as myprogram. Otherwise, /path/to/myprogram will also work.
@bigO Please have a general idea about computers and the OS you're using before starting programming, else you'll shoot yourself and others in the foot.
@bigO if you just type "myprogram", the shell will look in it's standard directories for executables, like /bin and /usr/bin. You need to specify the location, e.g., "./"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.