LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 09-16-2013, 10:18 AM   #1
Sud_paddy
LQ Newbie
 
Registered: Aug 2013
Posts: 12

Rep: Reputation: Disabled
bash: ./a.out: No such file or directory


I just install ubuntu 13.04 64 bit, and when m trying to run c program , i got same statement as follows:
gcc calc.c
./a.out calc.c
--> bash: ./a.out: No such file or directory

I also dont find a.out anywhere in file browser.

Before this i have ubuntu 13.04 32 bit.. there were no problem lyk this..
Plz. help me out of this...
 
Old 09-16-2013, 10:39 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Probably the proper forum for this is the software forum, you should move this if you have the option, or perhaps one of the moderators can/will do.

The default file which the gcc compiler creates is called a.out. You can alter this using the -o switch. Further, another good option is -ggdb to enable debugging via gdb.

It's hard to follow exactly what you typed and what you saw as output. But it also sounds as if you did this before on an earlier release and it did work.

Recommendations are that you can copy the text out of your command prompt and paste it into a response here, or add it as an attachment. Please place that within code comments, which are [ code] [ /code] when you type them in text, minus the leading spaces before the word "code".

Right now it sounds like because you've upgraded or changed versions, gcc or something it depends upon is not properly installed, or something has changed, such as a library version. Typing
Code:
gcc -v
to get the version will help. Also create a hello.c which is the simplest hello world application
Code:
#include <stdio.h>

void main(void)
{
    printf("Hello\n");
}
And compile it as following:

Code:
gcc -o hello hello.c
If it gives you an error, then something is simply wrong with the gcc install and therefore try to un-install and re-install gcc.

Because the output of the hello world experiment should give you an executable file named hello which you can run via ./hello and see "Hello" printed out.
 
1 members found this post helpful.
Old 09-16-2013, 12:17 PM   #3
Sud_paddy
LQ Newbie
 
Registered: Aug 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
I got again same problem...

avi@avi-Dell-System-XPS-L502X:~$ gcc -o hello hello.c

avi@avi-Dell-System-XPS-L502X:~$ ./hello.out hello

bash: ./hello.out: No such file or directory

avi@avi-Dell-System-XPS-L502X:~$

but how to remove and reinstall gcc. plz can u help me...
 
Old 09-16-2013, 12:26 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Why are you running ./hello.out?

You told gcc to name the executable "hello" with the -o flag, so you need to run "hello", not "hello.out". And why are you passing it a command line argument?

Code:
gcc -o hello hello.c
./hello
or
Code:
gcc hello.c
./a.out
That's it

Last edited by suicidaleggroll; 09-16-2013 at 12:27 PM.
 
3 members found this post helpful.
Old 09-16-2013, 12:53 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Suicidaleggroll, consider that they're learning, trying stuff, yes their questions are "off" or misplaced, however in contrast to my original recommendation, even though this fits with a software forum, they rightly did put a question to the newbie forum because ... they're new at this.

Sud_paddy, as Suicidaleggroll is pointing out, you do not need an argument, at least in this example case.

The default result of a gcc compile is "a.out" which is an executable. You run it as shown in Suicidaleggroll's response.

If you change the output file using the -o directive, then the chosen name is the executable.

To run a C program executable, you call the name of it; however if the current working directory is not in your $PATH, then you need to use "./" before the name, as you have been using.

If you were to structure a C program with an argument list, the program could require passing arguments.

For example:

Code:
#include <stdio.h>

void main(int argc, char **argv)
{
    // Code
}
This is the basic form to "create" a C executable which "supports" arguments. However if the code in that file doesn't use or check the arguments, then the program will still run. The author of the code can check the value of argc, it tells the number of arguments which were passed when the program was run. Using the **argv string array pointer, one can extract the arguments, or the arguments can also be grabbed using other means; such as getopt(3).

When I say getopt(3), because if you try to obtain the manpage for getopt, you will get getopt(1) as the first one. And that's the command line version of getopt. If you either do:
Code:
man -S 3 getopt
or:
Code:
man -a getopt
then you will see either "the" specific one you want, or you'll see all available man pages related to getopt, that your system knows about.

I think I'd recommend a few things here.

1. It seems as if you're experimenting with C programming and command line compilation. Refer to some of these: http://www.linfo.org/create_c1.html
http://www.linfo.org/create_c2.html

2. Bear in mind that although at the start, a lot of it is "do this", "next do this" the whole point of introductory tutorials are that you learn the basics and then be able to grow from there.

3. Next you ought to learn sufficient information about the Linux command shell. Learn about the $PATH environment, file privileges and so forth. Try this link:
http://linuxcommand.org/learning_the_shell.php

Reference (3) will help you to understand how to enter commands, know what to do with them, and understand what file permissions, ownership mean to you.

Best of luck. Once you get through this stepping stone and can run the code you originally intended to run, you probably should mark this thread as solved and create new threads with further questions. But do make sure you understand enough to get your answer now before closing this thread.
 
1 members found this post helpful.
Old 09-21-2013, 02:17 AM   #6
Sud_paddy
LQ Newbie
 
Registered: Aug 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thank u... both rtmistler and suicidaleggroll....
 
Old 09-21-2013, 07:41 AM   #7
zeebra
Senior Member
 
Registered: Dec 2011
Distribution: Slackware
Posts: 1,830
Blog Entries: 17

Rep: Reputation: 638Reputation: 638Reputation: 638Reputation: 638Reputation: 638Reputation: 638
Quote:
Originally Posted by suicidaleggroll View Post
Why are you running ./hello.out?

You told gcc to name the executable "hello" with the -o flag, so you need to run "hello", not "hello.out". And why are you passing it a command line argument?

Code:
gcc -o hello hello.c
./hello
Code:
gcc hello.c
./a.out
Sud_Paddy:
This is the correct way of doing it. At least for your current purpose. The "-o filename" option is to call a file something else than "a.out". "a.out" is the standard filename for a C file compiled with GCC. If you follow the second example above, it will just call the executable file "a.out". So you have to just open the correct file as described above, depending on the method you used.


There is a lot of information available online for C programming, many tutorials and good resources.

I can recommend a few books as well: C primer plus and beginning C (from novice to professional). These two books start out with the elementary and works their way to quite advanced C programming. Easy to understand for a beginner and very clear and good explenations.

Last edited by zeebra; 09-21-2013 at 07:45 AM.
 
1 members found this post helpful.
  


Reply



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
-bash: ./a.out: No such file or directory saritha Linux - Newbie 6 07-16-2018 11:28 PM
Bash: No such file or directory fqaiser Linux - Newbie 5 11-19-2012 10:20 PM
[SOLVED] Bash: No such file or directory, when file actually exists. SkyerSK Linux - Software 13 02-06-2011 04:33 AM
file or directory? bash script efus Programming 3 04-26-2007 06:11 PM
bash: cd: My: No such file or directory Doug.Gentry Fedora 2 12-05-2004 02:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:27 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
Open Source Consulting | Domain Registration