Compiling C in linux

Status
Not open for further replies.

cynosure

UbuntuUser
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?
 
Last edited:

mehulved

18 Till I Die............
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

Burning Bright
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
 

~Phenom~

The No.1 Stupid
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 ??
 

~Phenom~

The No.1 Stupid
^^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.
 

mehulved

18 Till I Die............
~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

"The Gentleman"
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 :)
 
Status
Not open for further replies.
Top Bottom