ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi I'm trying to learn C programming using a Fedora 12 system, I have gcc version 4.4.2 20091027 installed and I'm trying to use Nano as my text editor. I created the source code for hello, world and saved it as hello.c, I then compiled it using
Code:
$ gcc hello.c
a.out was then created but when I type
Code:
$ a.out
to execute it I get this
Code:
$ bash: a.out: command not found
Please help me find what I'm missing or not doing.
But it would be easier if you are standing in the directory where you create the hello.c file and where the compiled version is (the a.out file). If this is the case, jiml8's original answer works.
BTW: you might want to include the -o <name> option, this creates a more readable c file. I.e.: gcc hello.c -o hello, will create an executable hello file instead of a plain a.out.
~/a.out only works if the file is in the root of his home directory.
Basically, cd into the directory where you compiled the file. ./filename means "execute filename which is in the current directory". If you are in that directory and you specified ./a.out then either the executable was created without execute permission (which would be very strange) or the executable was not created, which means the compiler bombed, or you created the executable using the -o option.
and if you can then see the hello.c and a.out, change to that subdirectory with
cd C_programmes
Then, just to make sure, list the new current directory with a simple
ls
to make sure that you have moved into the directory which contains hello.c and a.out.
When you are in the directory with a.out, you should be able to run it with
./a.out
You need to prefix the name of the executable with ./ because Linux does not look in the current directory for executable programs. There is a search path in your environment that Linux uses to search for executable commands, but, by default, that search path does not include your current directory.
OK.... IT WORKS.
I had to copy the hello.c file to C_programmes then compile it, then run it with ./a.out.
Thanks Arthur, I didn't know linux wouldn't execute from current directory.
Linux WILL execute from current directory but by default the bash shell does not include the current directory in the path. This is a security mechanism. To execute from the current directory, you have to preface the command with ./ to explicitly tell bash that you want the file in the current directory.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.