LinuxQuestions.org
Visit Jeremy's Blog.
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 02-19-2011, 08:46 AM   #1
sujitkulkarni
LQ Newbie
 
Registered: Feb 2011
Location: Pune, India
Distribution: Ubuntu 9.10
Posts: 29

Rep: Reputation: 0
Unable to use gcc


Hey, I am trying to use gcc. I need to compile a C prog. But I am unable to do. I have done this:

Code:
sujit@sujit-desktop:~$ gcc -Wall test.c
gcc: test.c: No such file or directory
gcc: no input files
sujit@sujit-desktop:~$
I even googled for this. But I think I am making some mistakes in specifying path. Plz assist!!
 
Old 02-19-2011, 08:56 AM   #2
goodhombre
Member
 
Registered: Mar 2010
Location: Ungheni, Rep. Moldova
Distribution: Ubuntu
Posts: 89

Rep: Reputation: 22
Hi,

test if the the file is in the current directory before compiling it:
Code:
ls test.c
 
Old 02-19-2011, 08:59 AM   #3
sujitkulkarni
LQ Newbie
 
Registered: Feb 2011
Location: Pune, India
Distribution: Ubuntu 9.10
Posts: 29

Original Poster
Rep: Reputation: 0
umm i tried! but it says:
Code:
sujit@sujit-desktop:~$ ls test.c
ls: cannot access test.c: No such file or directory
well, the file test.c is on my desktop! so any clue?
 
Old 02-19-2011, 09:05 AM   #4
goodhombre
Member
 
Registered: Mar 2010
Location: Ungheni, Rep. Moldova
Distribution: Ubuntu
Posts: 89

Rep: Reputation: 22
Hi,

Likely you are in the you home directory.
Try:
Code:
cd Desktop
ls test.c
You ca find out which is the current working directory by using pwd command.

To switch to you home directory use ~
Code:
cd ~
cd Desktop
ls test.c
gcc -Wall test.c
 
1 members found this post helpful.
Old 02-19-2011, 09:07 AM   #5
sujitkulkarni
LQ Newbie
 
Registered: Feb 2011
Location: Pune, India
Distribution: Ubuntu 9.10
Posts: 29

Original Poster
Rep: Reputation: 0
Thanks it worked! THX A LOT!!!!!!!!!!!!
Code:
sujit@sujit-desktop:~$ cd Desktop
sujit@sujit-desktop:~/Desktop$ ls test.c
test.c
sujit@sujit-desktop:~/Desktop$ gcc -Wall test.c
sujit@sujit-desktop:~/Desktop$
NOW HOW TO RUN THE PROG?
 
Old 02-19-2011, 09:15 AM   #6
sujitkulkarni
LQ Newbie
 
Registered: Feb 2011
Location: Pune, India
Distribution: Ubuntu 9.10
Posts: 29

Original Poster
Rep: Reputation: 0
Question

Also tell me, does conio.h and void main() work? coz it is giving me error, and its asking for int main() instead of void main().

Code:
/* FILE: test.c */
#include <stdio.h>

void main()
{
	printf("Hi!!!!!!!!!");
	
}
 
Old 02-19-2011, 09:15 AM   #7
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,299
Blog Entries: 61

Rep: Reputation: Disabled
Try this:
Code:
gcc -Wall test.c -o test
./test
 
Old 02-19-2011, 09:17 AM   #8
goodhombre
Member
 
Registered: Mar 2010
Location: Ungheni, Rep. Moldova
Distribution: Ubuntu
Posts: 89

Rep: Reputation: 22
Hi,

Try :
Code:
chmod +x a.out
./a.out
You can specify the name of the output file by using -o option.
Code:
gcc -Wall test.c -o test.out
In most on the cases you have to make file executable using chmod +x , see man chmod form more details.
 
Old 02-19-2011, 09:23 AM   #9
goodhombre
Member
 
Registered: Mar 2010
Location: Ungheni, Rep. Moldova
Distribution: Ubuntu
Posts: 89

Rep: Reputation: 22
Quote:
Originally Posted by sujitkulkarni View Post
Also tell me, does conio.h and void main() work? coz it is giving me error, and its asking for int main() instead of void main().
conio.h doesn't exist under linux , you can use system("clear"); instead of clrscr().
Regarding void main , that is just a warning message, you can ignore him.
 
Old 02-19-2011, 09:26 AM   #10
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
Quote:
Originally Posted by brianL View Post
Try this:
Code:
gcc -Wall test.c -o test
./test
Wow! I never knew you were a programmer too!
 
Old 02-19-2011, 09:27 AM   #11
goodhombre
Member
 
Registered: Mar 2010
Location: Ungheni, Rep. Moldova
Distribution: Ubuntu
Posts: 89

Rep: Reputation: 22
Lol
 
Old 02-19-2011, 09:52 AM   #12
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,299
Blog Entries: 61

Rep: Reputation: Disabled
Quote:
Originally Posted by Anisha Kaul View Post
Wow! I never knew you were a programmer too!
That's about my limit as far as programming goes. I can edit "Hello World" programs (any language) to output "Hello Brian, you handsome devil!".
 
Old 02-19-2011, 02:11 PM   #13
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by brianL View Post
That's about my limit as far as programming goes. I can edit "Hello World" programs (any language) to output "Hello Brian, you handsome devil!".
Any language, even BF?
Code:
 ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.

Last edited by GrapefruiTgirl; 02-20-2011 at 08:59 AM. Reason: Changed to "BF" for language reasons ;)
 
Old 02-19-2011, 03:59 PM   #14
jayjwa
Member
 
Registered: Jul 2003
Location: NY
Distribution: Slackware, Termux
Posts: 787

Rep: Reputation: 250Reputation: 250Reputation: 250
What about LOLCODE?
 
Old 02-20-2011, 12:27 AM   #15
sujitkulkarni
LQ Newbie
 
Registered: Feb 2011
Location: Pune, India
Distribution: Ubuntu 9.10
Posts: 29

Original Poster
Rep: Reputation: 0
Thumbs up Thanks

thanks to everybody for answering me!
So the moral of the story is,
u get o/p by issuing ./filename or
chmod +x a.out
./a.out

commands. isnt it?
Also can I know how and why a.out is created?
 
  


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
[SOLVED] [6.7] Unable to build GCC-4.5.1 julien1486 Linux From Scratch 22 04-28-2011 06:54 AM
Unable to run GCC gileravxr Linux - Newbie 2 07-11-2009 02:10 AM
Unable to install GCC ???????? steelwire Linux - Newbie 10 04-24-2009 01:40 AM
unable to find gcc mohtasham1983 Linux - Newbie 8 10-17-2006 12:24 PM
unable to install gcc-2.96 vijaysh Debian 5 01-02-2005 07:41 AM

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

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