DIGIT-ARC read-only archive · snapshot: July 23, 2026

Compiling C in linux

16 posts · originally from https://geek.digit.in/community/threads/compiling-c-in-linux.63466/

cynosure
cynosure Original post #1
Jul 20, 2007 at 8:48 PM
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?
M
Jul 21, 2007 at 11:19 AM
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 *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.
anantkhaitan
Jul 21, 2007 at 12:40 PM
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 .. *anantkhaitan.googlepages.com/GCC.odt this is not my copied from somewhere..But still it is very helpful
cynosure
Jul 21, 2007 at 9:14 PM
Thanks man, Let me try.
Garbage
Garbage #5
Jul 21, 2007 at 9:34 PM
THanx Mehul, That PDF is really nice.
gary4gar
Jul 21, 2007 at 11:53 PM
Some good Guide that can teach you the basics of C???
M
Jul 22, 2007 at 12:03 AM
shirish_nagar said:
THanx Mehul, That PDF is really nice.
And the original author has encouraged people to share it and also add/correct information if possible.
~Phenom~
Jul 22, 2007 at 12:14 AM
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 ??
M
Jul 22, 2007 at 12:23 AM
As you'd do on cmd prompt on windows.
~Phenom~
~Phenom~ #10
Jul 22, 2007 at 12:34 AM
^^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.
M
mehulved #11
Jul 22, 2007 at 1:41 AM
~Phenom~ said:
^^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.
vish786
vish786 #12
Jul 22, 2007 at 2:02 AM
mehulved said:
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 *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 :)
cynosure
cynosure #13
Jul 22, 2007 at 10:46 AM
@Mehul: Thanks a ton. pdf file is goood.
praka123
praka123 #14
Jul 23, 2007 at 6:59 AM
for those who need an ide for C/Cpp compiling,can apt-get/yum install Anjuta.:)
M
mehulved #15
Jul 23, 2007 at 12:58 PM
praka123 said:
for those who need an ide for C/Cpp compiling,can apt-get/yum install Anjuta.:)
Why not emerge or pacman or something else?
QwertyManiac
Jul 23, 2007 at 6:53 PM
mehulved said:
Why not emerge or pacman or something else?
Is it really useful for someone to list all package managers there are? :confused: