LinuxQuestions.org
Help answer threads with 0 replies.
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 02-18-2007, 04:37 AM   #1
kentmaster
LQ Newbie
 
Registered: Feb 2007
Posts: 1

Rep: Reputation: 0
C programming problem


Hi, I am newbie in Linux. I just wrote simple C program to print out "hello world"
after I compiled, it created a.out file, then I tried to run it, but it said
bash : a.out: command not found.

My linux system is Fedora 6.0
Thanks
 
Old 02-18-2007, 04:45 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
You need to state how you got gcc to create the a.out file and how you are attempting to execute it. Direct pasting of commands used, and entire outputs thereof, is the accepted way to do this.

Are you sure a.out is a binary? (And not, say, object code?)
Did you remember to make the file executable?
Is the file in your path?

http://vergil.chemistry.gatech.edu/r...ial/intro.html

If your source code is in a file called "hello.c", then try the following commands:

$ gcc -ansi -pedantic -Wall -O2 -o hello hello.c

(creates an executable "hello" in the same directory, and also makes sure you have done everything else OK. This is a good way to start out, the compiler will tell you about every mistake you make.)

$ chmod a+x hello

(make "hello" executable so you can run it)

$ ./hello

(since "hello" is unlikely to be in your PATH environment variable, you need to tell linux where to go look for it. The dot says "look right here".)

Last edited by Simon Bridge; 02-18-2007 at 04:58 AM.
 
Old 02-18-2007, 04:49 AM   #3
cad
Member
 
Registered: Dec 2006
Distribution: Fedora core 4
Posts: 92

Rep: Reputation: 15
May be the current directory is not in your path
Try ./a.out and if it works then make change in your .profile or .bashrc in the home folder as :
PATH=$PATH:.
The . signifies current directory in both the cases
 
  


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
Qt Programming Problem chanwing Programming 7 04-20-2005 05:18 AM
pthread's programming problem keiwu Programming 3 02-14-2005 02:17 AM
another c programming problem Randall Programming 8 01-29-2003 05:45 PM


All times are GMT -5. The time now is 11:09 AM.

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