SUM: Help for a novice

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks to Oliver and Rupert for their answers.  I really appreciate the
help.  I'm sure I will be seeking the groups help as I work through my class
this fall.

Mike


a.out is the executable. If you do not use the compiler option "-c",
then no object files are created, but only the executable.

Just run it with

./a.out

Oliver

This is the final executable. (It's a historical name - "assembler out".)
You can run it with

    ./a.out

Note the leading "./" is important - it will be necessary unless you have
'.' in your PATH environment. If you want to change the name generated, add

    -o <output file name>

to your command line.

> Is linking the process used to create an executable from an object
> file?

Yes. Note that g++ is actually the "compiler driver"; what really happens is

    * you invoke g++
        * g++ invokes cc1plus to compile the code
            * cc1plus generates a temporary assembler file
            * cc1plus invokes as to assemble to an object file
        * g++ invokes ld (or collect2) to link the object file into
          an executable, using a predefined set of libraries.

If you want to see all of this in action, add '-v' to your compile line. If
you want to compile your C++ into assembler and not assemble or link, add
'-S' to your compile line. If you want to compile your C++ into an object
file, add '-c' to your command line. If you want to link C++ object file(s)
and libraries, it's better feed them into g++ rather than trying to use ld
yourself.

Note that you almost certainly want to add '-Wall' to your compile line to
get compiler warnings, and you want at least one of '-g' to add debugging
information to your build or '-O2' to optimize the code; g++ defaults to no
optimization.

You can get help on the flags g++ supports with

   g++ --help

or looking in the manual; there's a copy at http://gcc.gnu.org/onlinedocs/

Good luck,
Rup.

> I recently installed gcc version 3.3 on Redhat 7.3 kernel 2.4.18-3.  I am
> taking an introductory c++ class this fall and I wanted to get a head
start
> on compiling my c++ programs.  I compiled my program (without error) with
> the following command:
> 
> g++ first.cpp
> 
> It produced a file called a.out.  Is this the object file?  How do I
convert
> this file into an executable file?  Is linking the process used to create
an
> executable from an object file?  
> 
> Forgive my ignorance surrounding this question.  Any help would be greatly
> appreciated.
> 
> Mike Badar
> ESRI-Denver
> One International Ct.
> Broomfield, CO  80021-3200
> 303-449-7779
> mbadar@xxxxxxxx
> www.esri.com

Mike Badar
ESRI-Denver
One International Ct.
Broomfield, CO  80021-3200
303-449-7779
mbadar@xxxxxxxx
www.esri.com


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux