-
gcc compilers
Hi,
Does anybody know how a gcc compilter work? I've been typing in commands like: (and have no clue what I'm doing)
g++ -c something.cc
gcc -c something.cc
What's the difference above?
g++ -o thing.o thing2.o thing3.o
what are the .o files? and what does the above command give me ultimately?
Thx...
-
Well first of all, all the info you need for gcc compilers is gotten with this line
$man gcc
OR
$man g++
OR
$info gcc
OR
$info g++
Second, a basic use of the file command is
$gcc source.c
OR
$g++ source.cpp
This creates an executable called a.out.
If you want to name it.
Try
$gcc source.c -o output.exe
OR
$g++ -o output source.cpp
As you can see order doesn't make a difference, as long as the file directly after the -o is the name of the executable you wanna create, and two they don't have to have extensions to be executable.
BTW to run the program type
$./progName
That is dot-slash-progName
this should get you going, for more info check the man pages (the stuff right at the top)
Best o Luck
kwigibo
-
Hi,
Thanks for the reply,
but what if I have something like:
g++ -o a.out source.o source2.o
I'm guessing this would create an executable file call a.out using the two source file source.o and source2.o....but what are the ".o" file?
It would make more sense if I had:
g++ - o a.out source.cc source2.cc
So here, I'm creating a a.out file using the two c++ source code and I'm guessing that one of the 2 source code has a "main" function...
Please correct me if I'm wrong,....I'm a little confused :)
-
Compilation for c++ is done in two stages.
First each file is translated into object code (not quite machine level).
Then the files are linked together into a single exe which is translated into native code.
A file with extension .o is object code.
-
But where do I get the .o files from?
Are you saying that if I create a class, then I would get the .o file form compiling the .cc file. Maybe then I compile a couple more .cc files to get a couple more .o files. Then I would create a.out by linking all the .o files?
Can't I just go from .cc to a.out??
-
>>Can't I just go from .cc to a.out??
Yes but sometimes you may want to link other things into it.
Or if your'e only working on one file, only having to compile that one and simply linking the rest is much faster.