gcc compilers

This is a discussion on gcc compilers within the C++ Programming forums, part of the General Programming Boards category; Hi, Does anybody know how a gcc compilter work? I've been typing in commands like: (and have no clue what ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    51

    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...
    Which is the master, which is the student?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Location
    Australia
    Posts
    212
    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

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    51
    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
    Which is the master, which is the student?

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    381
    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.
    If you own a piece of land and there is an volcano on it and it ruins a
    nearby town, do you have to pay for the property damage?

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    51
    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??
    Which is the master, which is the student?

  6. #6
    Registered User
    Join Date
    Jan 2002
    Posts
    381
    >>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.
    If you own a piece of land and there is an volcano on it and it ruins a
    nearby town, do you have to pay for the property damage?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Replies: 4
    Last Post: 09-02-2007, 08:47 PM
  3. Compiles on gcc 3.3 but not on gcc 4.0.3
    By cunnus88 in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2007, 12:24 PM
  4. Replies: 13
    Last Post: 10-02-2005, 09:29 PM
  5. gcc
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-22-2003, 03:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21