LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-03-2004, 03:19 AM   #1
RadiantBANE
LQ Newbie
 
Registered: Jan 2004
Posts: 6

Rep: Reputation: 0
hello world wont run when i type a.out???


I'm pretty new to c programming so i started out with hello world and followed a guide from a newbie site. so heres the code:

#include <stdio.h>

int main() {
printf("Hello World!\n");
return 0;
}

Copied and pasted, and compiles when i type:


[ruben@localhost ruben]$ gcc helloworld.c
[ruben@localhost ruben]$

then i attempt to run the program, (by default named a.out)

[ruben@localhost ruben]$ a.out
bash: a.out: command not found

so i attempt to name it and run it

[ruben@localhost ruben]$ gcc helloworld.c -o world
[ruben@localhost ruben]$ world
bash: world: command not found

Can anyone help me out and let me know what im doing wrong? I'm running Red Hat 9 with an uncompiled kernel, freshly installed with all the programming aps installed. Any suggestions would help. Thanks!
 
Old 01-03-2004, 03:21 AM   #2
poison
Member
 
Registered: Dec 2003
Location: Layer 7 =D
Distribution: Slackware, LFS, Rock Linux
Posts: 165

Rep: Reputation: 30
chmod a+x ./a.out
./a.out
 
Old 01-03-2004, 03:23 AM   #3
RadiantBANE
LQ Newbie
 
Registered: Jan 2004
Posts: 6

Original Poster
Rep: Reputation: 0
[ruben@localhost ruben]$ chmod a+x ./a.out
chmod: failed to get attributes of `./a.out': No such file or directory
[ruben@localhost ruben]$ ./a.out
bash: ./a.out: No such file or directory
[ruben@localhost ruben]$
 
Old 01-03-2004, 03:24 AM   #4
arunshivanandan
Member
 
Registered: May 2003
Location: Kerala,India
Distribution: RedHat,Mandrake,Debian
Posts: 643

Rep: Reputation: 30
try './a.out' or './world'.(it is DOTSLASH)
this ./ is the present working directory,and so by giving this,you are mentioning the full path.if you want to run it by just mentioning a.out,then you will have to include the particular directory in your PATH.
 
Old 01-03-2004, 03:25 AM   #5
RadiantBANE
LQ Newbie
 
Registered: Jan 2004
Posts: 6

Original Poster
Rep: Reputation: 0
sorry about that, recompile with a.out as name worked, what did that command do?

chmod a+x ./a.out

thanks a lot for the help!
 
Old 01-03-2004, 03:26 AM   #6
arunshivanandan
Member
 
Registered: May 2003
Location: Kerala,India
Distribution: RedHat,Mandrake,Debian
Posts: 643

Rep: Reputation: 30
sorry,i was quite late with that post.
make sure that there is the file a.out.(ls will show it)
 
Old 01-03-2004, 03:27 AM   #7
arunshivanandan
Member
 
Registered: May 2003
Location: Kerala,India
Distribution: RedHat,Mandrake,Debian
Posts: 643

Rep: Reputation: 30
again i am late.never mind.
 
Old 01-03-2004, 03:35 AM   #8
poison
Member
 
Registered: Dec 2003
Location: Layer 7 =D
Distribution: Slackware, LFS, Rock Linux
Posts: 165

Rep: Reputation: 30
chmod a+x <file>
markes that file as beeing an executable...
it's the safest way to start an executable thats not in your path by specifying the absolute path, since youre cl could get confused, saying you have just compiled a program thats named configure
when you now type configure your shell wouldnt know if it should run the executable located in your path (echo $PATH) or the one you compiled...
which could lead to serious damages....
thus, you specify the full path, if your in that directory, thats ./ for your current working directory (~/ would represent your home dir)

regards
happy hacking ^^
 
Old 01-03-2004, 08:35 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,929

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
BTW when you compile the program the permissions should be already set as executable. All you have to do to run the program is add the ./
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Atlas or World Map type software for Linux - is there any? shazam75 Linux - Software 0 11-26-2005 03:58 AM
Download ,run file type wazntme Linux - Newbie 1 10-27-2005 12:57 PM
run World at War degraffenried13 Linux - Games 1 05-16-2005 12:22 PM
Trying to run photoshop in wine. Install, but wont run. bruno buys Linux - Software 14 07-15-2004 05:30 PM
The wide world of scripts run at startup, big question here SrConchiwa Linux - General 5 07-18-2003 09:09 AM


All times are GMT -5. The time now is 10:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration