LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 07-14-2010, 08:58 PM   #1
kah64
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Rep: Reputation: 0
Exclamation Issue GCC file not found


Hi.
I'm new to linux. Just installed Ubuntu and bought my first programming book.

I installed Emacs and gcc, then I make the following steps:

Open a terminal
go to Emacs
write basic code (Hello World)
Save it as hello
Control + C

at the terminal I wrote:

gcc -o hello hello.c

chili@ubuntu:~$ gcc -o hello hello.c
gcc: hello.c: No such file or directory
gcc: no input files

Been searching posts and still not been able to find the problem.

I hope you can help me.
BR,

KaH64
"Crisis + Opportunity = Cris-atunity"
 
Old 07-14-2010, 09:00 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hi, welcome to LQ!

Why would you expect to find "hello.c" if you save "hello"?



Cheers,
Tink
 
Old 07-14-2010, 09:02 PM   #3
navaneethkn
LQ Newbie
 
Registered: Jul 2005
Location: india
Posts: 12

Rep: Reputation: 0
You have saved the file without an extension. Try saving it as "hello.c". Emacs won't assign an extension automatically. In linux, file extensions are not required.
 
Old 07-14-2010, 09:04 PM   #4
navaneethkn
LQ Newbie
 
Registered: Jul 2005
Location: india
Posts: 12

Rep: Reputation: 0
Alternatively, emacs has got a nice feature where it generates the compilation statements. If your file name is "hello.c", type "M-x compile" and "make -k hello" which will take "hello.c", compile and produce an executable named "hello".
 
Old 07-14-2010, 09:07 PM   #5
kah64
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Hi Tink

I been following the steps in the book (yeah, shame shame hahaha). I understood that to compile the code i write in Emacs, I needed to save it as any file (e.i. hello) and the go to terminal and run gcc -o filename_given_in_emacs filename_output_for_compiler.c

What am i doing wrong? does the emacs already compile it when I save it?? i try to run it but it says hello:command not found

BR,

KaH64
"Crisis + Opportunity = Cris-atunity"
 
Old 07-14-2010, 09:13 PM   #6
navaneethkn
LQ Newbie
 
Registered: Jul 2005
Location: india
Posts: 12

Rep: Reputation: 0
"emacs" is just an editor. When saving a file, it won't compile it. "gcc" is the compiler which does that. All emacs does is to invoke gcc with the commands you give.

Code:
gcc hello.c -o hello
generates executable file "hello". To run it you need to do, "./hello". From emacs press Alt + Shift + ! and type "./hello".

Last edited by navaneethkn; 07-14-2010 at 09:14 PM.
 
Old 07-14-2010, 09:17 PM   #7
kah64
LQ Newbie
 
Registered: Jul 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Hi navaneethkn

I followed your suggestion and the one from Tink and it seems that is both of it, first name the file with an extension, then nale after the -o filename_saved_in_emacs

Thank you very much!!

BR

KaH64
"Crisis + Opportunity = Cris-atunity"
 
Old 07-14-2010, 09:23 PM   #8
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Please try this:
1. Start emacs however is convenient for you.
Cut/paste the following code:
Code:
#include <stdio.h>

int
main (int argc, char *argv[])
{
  printf ("Hello world!\n");
  return 0;
}
2. Save with a specific filename and directory path:
<Ctl-x><Ctl-w>
Save to: /tmp/hello.c

3. From a command prompt, "cd" to that directory and compile the program:
Quote:
cd /tmp
gcc -g -Wall -pedantic hello.c -o hello
ls -l hello*
Quote:
-rwxr-xr-x 1 paulsm users 7677 2010-07-14 22:48 hello
-rw-r--r-- 1 paulsm users 99 2010-07-14 22:47 hello.c
4. Run the program:
Quote:
./hello
Quote:
Hello world!

'Hope that helps .. PSM

Last edited by paulsm4; 07-15-2010 at 12:50 AM.
 
Old 07-14-2010, 11:55 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by kah64 View Post
Hi Tink

I been following the steps in the book (yeah, shame shame hahaha). I understood that to compile the code i write in Emacs, I needed to save it as any file (e.i. hello) and the go to terminal and run gcc -o filename_given_in_emacs filename_output_for_compiler.c

What am i doing wrong? does the emacs already compile it when I save it?? i try to run it but it says hello:command not found

BR,

KaH64
"Crisis + Opportunity = Cris-atunity"

You got the filenames the wrong way round. The one with
the "-o" is the OUTPUT file the compiler is supposed to
generate. C is program source. So if you save from
emacs as hello.c (or simply rename the one already
saved with "mv hello hello.c") and re-run your command
all will be well.


Cheers,
Tink
 
1 members found this post helpful.
  


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
gcc Error ,executing .c file-> crt1.o not found Santoshkb Linux - Server 5 06-23-2012 04:49 AM
GCC not found QianChen Linux - Newbie 1 07-19-2006 04:49 PM
GCC not found? newuser455 Linux - Software 4 06-27-2005 02:55 AM
gcc vs. g++ -> iostream lib found vs. not found CooManChu Linux - General 1 12-11-2004 09:20 AM
gcc / cc etc not found ! realos Linux - Software 6 07-25-2002 04:42 AM


All times are GMT -5. The time now is 01:02 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