 |
20-07-2007, 08:48 PM
|
#1 (permalink)
|
|
UbuntuUser
Join Date: Sep 2006
Location: India
Posts: 746
|
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
|
|
|
|
Advertisements. Register and be a member of the community to get rid of them.
|
|
Advertisement
|
|
21-07-2007, 11:19 AM
|
#2 (permalink)
|
|
18 Till I Die............
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
|
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
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.
|
|
|
21-07-2007, 12:40 PM
|
#3 (permalink)
|
|
Burning Bright
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
|
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/
|
|
|
21-07-2007, 09:14 PM
|
#4 (permalink)
|
|
UbuntuUser
Join Date: Sep 2006
Location: India
Posts: 746
|
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.
|
|
|
21-07-2007, 09:34 PM
|
#5 (permalink)
|
|
God of Mistakes...
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
|
Re: Compiling C in linux
THanx Mehul, That PDF is really nice.
|
|
|
21-07-2007, 11:53 PM
|
#6 (permalink)
|
|
GaurishSharma.com
Join Date: May 2005
Location: Jaipur
Posts: 4,116
|
Re: Compiling C in linux
Some good Guide that can teach you the basics of C???
|
|
|
22-07-2007, 12:03 AM
|
#7 (permalink)
|
|
18 Till I Die............
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
|
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.
|
|
|
22-07-2007, 12:14 AM
|
#8 (permalink)
|
|
The No.1 Stupid
Join Date: May 2005
Location: CYBERYARD
Posts: 1,708
|
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...
|
|
|
22-07-2007, 12:23 AM
|
#9 (permalink)
|
|
18 Till I Die............
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
|
Re: Compiling C in linux
As you'd do on cmd prompt on windows.
|
|
|
22-07-2007, 12:34 AM
|
#10 (permalink)
|
|
The No.1 Stupid
Join Date: May 2005
Location: CYBERYARD
Posts: 1,708
|
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...
|
|
|
22-07-2007, 01:41 AM
|
#11 (permalink)
|
|
18 Till I Die............
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
|
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.
|
|
|
22-07-2007, 02:02 AM
|
#12 (permalink)
|
|
"The Gentleman"
Join Date: Sep 2006
Posts: 1,434
|
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
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
|
|
|
22-07-2007, 10:46 AM
|
#13 (permalink)
|
|
UbuntuUser
Join Date: Sep 2006
Location: India
Posts: 746
|
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.
|
|
|
23-07-2007, 06:59 AM
|
#14 (permalink)
|
|
left this forum longback
Join Date: Sep 2005
Location: -
Posts: 7,536
|
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
|
|
|
23-07-2007, 12:58 PM
|
#15 (permalink)
|
|
18 Till I Die............
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
|
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?
|
|
|
23-07-2007, 06:53 PM
|
#16 (permalink)
|
|
Commander in Chief
Join Date: Jul 2005
Posts: 6,658
|
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
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|