delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/07/10:32:31

From: George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Newbie question, everyone should know this I don't.
Date: 7 Nov 1997 13:30:38 GMT
Organization: Oxford University, England
Lines: 26
Message-ID: <63v55u$d7o$1@news.ox.ac.uk>
References: <63ul58$ars$1 AT news DOT sas DOT ab DOT ca>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On 7 Nov 1997 08:57:12 GMT in comp.os.msdos.djgpp
steven AT freenet DOT edmonton DOT ab DOT ca wrote:

: What's the difference between linking and compiling? I know what compiling
: is... but linking is uncharted territory for myself.

Compilation is turning your C source code into object files, which
contain machine code, data, symbol names, etc.  They're not
executable.  Linking is combining several object files, along with any
libraries needed (e.g. the standard C library), to produce a file
which can be executed.

The difference is only really apparent when you use several source
files and tell gcc explicitly to do the compiling/linking in two
stages; if you specify `-c', it will compile only, leaving you with a
.o object file for each .c or .cc source file.  Then you can call it
again, passing these .o files and suitable arguments, to get an
executable file.

gcc -c file1.c file2.c             (compiles only, creating file1.o and file2.o)
gcc file1.o file2.o -o output.exe  (links the two object files to form the executable)

-- 
Regards,

george DOT foot AT merton DOT oxford DOT ac DOT uk

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019