This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Help for a novice
- From: "Rupert Wood" <me at rupey dot net>
- To: "'Mike Badar'" <mbadar at esri dot com>
- Cc: <gcc-help at gcc dot gnu dot org>
- Date: Mon, 4 Aug 2003 15:38:13 +0100
- Subject: RE: Help for a novice
Mike Badar wrote:
(Beaten to it, but there's some other stuff here too.)
> 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?
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.