Forum     

Go Back   Digit Technology Discussion Forum > Software > Open Source
Register FAQ Calendar Mark Forums Read

Open Source A place where you can talk to like-minded people about the fastest growing software movement today! Discuss anything and everything about Open Source software and Operating Systems.


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 20-07-2007, 08:48 PM   #1 (permalink)
UbuntuUser
 
cynosure's Avatar
 
Join Date: Sep 2006
Location: India
Posts: 746
Default


I am new to programming and am using an ebook to learn C.
I am crafting my first program i.e "Hello World"
I compiled the program using gcc and--like the ebook described--I compiled it correctly using "gcc -c Hello.c" and got a Hello.o file.
The ebook further said that if I use "gcc Hello.c" then I will get the linked form of the file. I used the same command and got an a.out file.
So my queries are:
1) How can I link an .o file directly using gcc or any other linker?
2) What exactly needs to be done with the a.out file?
__________________
Core 2 Quad Q6600 G0, XFX 650i ultra, XFX 8600GT 512MB, Seagate 320GB, Altec Lansing ATP3, 2x1GB 800MHz, 19" Viewsonic VA1912WB, LiteOn DVD burner, Logitech K/B, mouse, Amigo 500W PSU, Local Cabby.

Last edited by cynosure; 21-07-2007 at 08:24 AM. Reason: Compiling C in linux
cynosure is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 21-07-2007, 11:19 AM   #2 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Compiling C in linux

1)I don't think gcc is the linker. It's ld that you're looking for. Though you can link a library to your program by passing -l parameter to gcc
Code:
gcc Hello.c -lm
It will link math library.
Please correct me if I am wrong. I am not so proficient with these things.
2)execute it. It's the executable. You can give it your own name by passing -o parameter to gcc
Code:
gcc Hello.c -o Hello
That will create an executable Hello.
Check the pdf at http://people.ubuntu-in.org/~ghoseb/tc-to-gcc.pdf for more info. It's supposed to be for those people who come from tc to gcc. But, it is also very much helpful to those starting out with gcc, like me.
mehulved is offline  
Old 21-07-2007, 12:40 PM   #3 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Re: Compiling C in linux

Yes for compiling C codes use:
Code:
$ gcc -W <filename.c> -o <executablename>
But various other parameters(specifying libraries etc) required if you include math.h and others
Run :
Code:
$ ./<executablename>
Also follow this .. http://anantkhaitan.googlepages.com/GCC.odt this is not my copied from somewhere..But still it is very helpful
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 21-07-2007, 09:14 PM   #4 (permalink)
UbuntuUser
 
cynosure's Avatar
 
Join Date: Sep 2006
Location: India
Posts: 746
Default Re: Compiling C in linux

Thanks man, Let me try.
__________________
Core 2 Quad Q6600 G0, XFX 650i ultra, XFX 8600GT 512MB, Seagate 320GB, Altec Lansing ATP3, 2x1GB 800MHz, 19" Viewsonic VA1912WB, LiteOn DVD burner, Logitech K/B, mouse, Amigo 500W PSU, Local Cabby.
cynosure is offline  
Old 21-07-2007, 09:34 PM   #5 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: Compiling C in linux

THanx Mehul, That PDF is really nice.
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 21-07-2007, 11:53 PM   #6 (permalink)
GaurishSharma.com
 
gary4gar's Avatar
 
Join Date: May 2005
Location: Jaipur
Posts: 4,116
Default Re: Compiling C in linux

Some good Guide that can teach you the basics of C???
gary4gar is offline  
Old 22-07-2007, 12:03 AM   #7 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Compiling C in linux

Quote:
Originally Posted by shirish_nagar
THanx Mehul, That PDF is really nice.
And the original author has encouraged people to share it and also add/correct information if possible.
mehulved is offline  
Old 22-07-2007, 12:14 AM   #8 (permalink)
The No.1 Stupid
 
~Phenom~'s Avatar
 
Join Date: May 2005
Location: CYBERYARD
Posts: 1,708
Default Re: Compiling C in linux

and can anyone tell me how to run a java program in linux, without using any IDE like Eclipse as its too heavy and confusing ??
__________________
n00b forever...
~Phenom~ is offline  
Old 22-07-2007, 12:23 AM   #9 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Compiling C in linux

As you'd do on cmd prompt on windows.
mehulved is offline  
Old 22-07-2007, 12:34 AM   #10 (permalink)
The No.1 Stupid
 
~Phenom~'s Avatar
 
Join Date: May 2005
Location: CYBERYARD
Posts: 1,708
Default Re: Compiling C in linux

^^i tried it the same way long time ago , didnt worked . then also tried Eclipse , that too was too complex to understand and heavy too.
how to set those home variables , environment cariables , etc ?? I cudnt program succesfully in Linux thats the main reason , i Still have XP on my machine along with ubuntu.

PS: I successfully made and run a simple "print hello" program in linux in C using gcc , just for test purposes.
__________________
n00b forever...
~Phenom~ is offline  
Old 22-07-2007, 01:41 AM   #11 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Compiling C in linux

Quote:
Originally Posted by ~Phenom~
^^i tried it the same way long time ago , didnt worked . then also tried Eclipse , that too was too complex to understand and heavy too.
how to set those home variables , environment cariables , etc ?? I cudnt program succesfully in Linux thats the main reason , i Still have XP on my machine along with ubuntu.
Is jdk installed?
Code:
sudo apt-get install sun-java6-jdk
paths are configured fine, no need to set it up, it's done automatically by package manager.
mehulved is offline  
Old 22-07-2007, 02:02 AM   #12 (permalink)
"The Gentleman"
 
vish786's Avatar
 
Join Date: Sep 2006
Posts: 1,434
Default Re: Compiling C in linux

Quote:
Originally Posted by mehulved
1)I don't think gcc is the linker. It's ld that you're looking for. Though you can link a library to your program by passing -l parameter to gcc
Code:
gcc Hello.c -lm
It will link math library.
Please correct me if I am wrong. I am not so proficient with these things.
2)execute it. It's the executable. You can give it your own name by passing -o parameter to gcc
Code:
gcc Hello.c -o Hello
That will create an executable Hello.
Check the pdf at http://people.ubuntu-in.org/~ghoseb/tc-to-gcc.pdf for more info. It's supposed to be for those people who come from tc to gcc. But, it is also very much helpful to those starting out with gcc, like me.
hey thanks for the pdf link... downloadin now
__________________
"The use of COBOL cripples the mind; its teaching should, therefore, be regarded as a criminal offense."
- Dijkstra
vish786 is offline  
Old 22-07-2007, 10:46 AM   #13 (permalink)
UbuntuUser
 
cynosure's Avatar
 
Join Date: Sep 2006
Location: India
Posts: 746
Default Re: Compiling C in linux

@Mehul: Thanks a ton. pdf file is goood.
__________________
Core 2 Quad Q6600 G0, XFX 650i ultra, XFX 8600GT 512MB, Seagate 320GB, Altec Lansing ATP3, 2x1GB 800MHz, 19" Viewsonic VA1912WB, LiteOn DVD burner, Logitech K/B, mouse, Amigo 500W PSU, Local Cabby.
cynosure is offline  
Old 23-07-2007, 06:59 AM   #14 (permalink)
left this forum longback
 
praka123's Avatar
 
Join Date: Sep 2005
Location: -
Posts: 7,536
Smile Re: Compiling C in linux

for those who need an ide for C/Cpp compiling,can apt-get/yum install Anjuta.
__________________
left this forum long back.Admin Can Delete this Account and posts Permanantly.Thank You
Get GNU/Linux - http://getgnulinux.org
praka123 is offline  
Old 23-07-2007, 12:58 PM   #15 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Compiling C in linux

Quote:
Originally Posted by praka123
for those who need an ide for C/Cpp compiling,can apt-get/yum install Anjuta.
Why not emerge or pacman or something else?
mehulved is offline  
Old 23-07-2007, 06:53 PM   #16 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Compiling C in linux

Quote:
Originally Posted by mehulved
Why not emerge or pacman or something else?
Is it really useful for someone to list all package managers there are?
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help me on Linux from Scratch (compiling binutils) cranky Open Source 3 28-04-2007 10:37 PM
Compiling in KDevelop saurabh.sauron Open Source 9 07-08-2006 06:30 PM
Compiling Linux Kernel + Installating SM56 Modem on RHL khandu Tutorials 5 03-08-2006 07:50 PM
Compiling yr own Linux--gentoolinux dabster Open Source 9 23-02-2006 10:31 PM
compiling kernel niranjan_mcarenyold Open Source 4 03-07-2005 01:05 PM

 
Latest Threads
- by Sujeet
- by soumya
- by clmlbx
- by Charan

Advertisement




All times are GMT +5.5. The time now is 12:49 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2