PDA

View Full Version : Can't compile simple c code


dave_567
March 12th, 2006, 10:15 PM
I've executed "sudo apt-get install build-essential" and tried a simple c program. I can get an a.out file. I looked and it seems to be executable, but I can't run it. Any ideas out there? :confused:


Me@ubuntu:~$ ls
Desktop Documents hello.c Images Internet Files School
me@ubuntu:~$ cat hello.c
#include<stdio.h>

main()
{
printf("\nHello World\n\n");
}
me@ubuntu:~$ gcc hello.c
me@ubuntu:~$ ls
a.out Desktop Documents hello.c Images Internet Files School
me@ubuntu:~$ a.out
bash: a.out: command not found
me@ubuntu:~$

Sutekh
March 12th, 2006, 10:17 PM
Try
./a.out
if its not executable use
chmod +x a.out

gord
March 13th, 2006, 03:53 AM
without the "./", the console will look in your binary path (ie: /usr/bin /usr/local/bin and the lot), not in your current directory

dave_567
March 13th, 2006, 04:54 AM
the ./ works. The program executes now. \\:D/ \\:D/

I guess that It would be better if I append my path to include this option perminently. I'm weak on bash shell scripting. any advice?

Also I'm using vi as the text editor. What else is out there? Something that is a bit more user friendly?

Sutekh
March 13th, 2006, 05:18 AM
the ./ works. The program executes now. \\:D/ \\:D/

I guess that It would be better if I append my path to include this option perminently. I'm weak on bash shell scripting. any advice?Glad its working.

Try this to add a folder to your $PATH

nano ~/.bashrc
Then add these two lines to it

PATH=$PATH:/<your>/<path>/
export PATH

Changing /<your>/<path>/ to whatever is appropriate for you.


Also I'm using vi as the text editor. What else is out there? Something that is a bit more user friendly?You'll get props for using vi though! Try pico, nano for editing from the command line (no desktop environment running) and gedit for a more graphical setup.

toojays
March 13th, 2006, 07:41 AM
And if you want to learn something useful, get to know the one true editor (http://www.gnu.org/software/emacs).

Sutekh
March 13th, 2006, 08:18 AM
How silly of me! How could I forget that!

dave_567
March 13th, 2006, 11:41 PM
Got it all working. Took a few minutes with nano to figure out how to save the file. but the format is simple and works well. I've never used emacs. I'll give it a look also.

Thanks for the help.

xenmax
March 20th, 2006, 05:00 AM
And if you want to run a.out from any directory it is present in , you could include '.' to your path which is obviously the present directory.
PATH=$PATH:.
export PATH